Codng - comparing data

  • Hi

    I'm tring to get the user to enter the correct information once they click on the cmdSave button.

    The data in the field can be changed but must link to the table or query. I keep getting the msgbox even if the data exists.

    Please HELP

    Private Sub cmdSave_Click()

        If Me.ClinicianID.Value <> "qryPatientCheck.ClinicianID" Then

        MsgBox "Please Type in a valid ID as data will not be saved"

        End If

       

    End If

    If Me.Dirty = True Then

        If MsgBox("Do you want to save the changes made?", vbYesNo, "Save") = vbYes Then

                    DoCmd.RunCommand acCmdSaveRecord 'save option - if yes save else do nothing

               

        End If

     End If

    end sub

  • assuming access97

    dim rs as dao.recordset

    dim sqlstring as string

    sqlstring="SELECT clinicianid from qryPatientCheck where ClinicianID= " & Me.ClinicianID.Value

    set rs=currentdb.openrecordset (sqlstring)

    if rs.recordcount>0 then

    'found

    else 'not found

    end if

    rs.close

    set rs=nothing

  • This does not work as there is no such thing as dao.recordset

  • If Forms![frmPatientCheck]![ClinicianID].Value <> Dlookup(FieldToReturn, TableName, Criteria) Then

    msgbox "not correct"

    end if

    this does not work as well .HELP ME PLEASE

  • Hi,
     
    Having some problems. Can anyone help me please much appreciate it.
     
     
     If Forms![frmPatientCheck]![ClinicianID].Value <> DLookup("ClinicianID", "tblClinician", "ClinicianID") Then

    MsgBox "Please enter the correct Clinician ID as data will only then be saved "
    End If

     
     
    when the ID is 1 then it works else the message will be displayed. This shouldn't happen. The message should be displayed when the number entered doesn't exist.
     
     

     
  • What technology you use to get your data ADO,DAO,.NET?

    Is this in VB6,Access,.NET?

    One of the 3 parameters of  DLookup is probably the value you wish to look up.

    *have a look at

    http://www.mvps.org/access/general/gen0018.htm

    If you are working in Access, we have a forum dedicated to Access here.

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply