I'm using the code that JoeAtWork provided earlier;(Thanks again JOe!) just the line that begins with "Nz". the rest is my hack job.
The event procedure opens a form "frm ADD to WARD" in hidden mode, which in turn opens a parameter query "qry ADD to WARD. This query prompts for an ID field value (number field). This ID field is named "MPI".
What I want to happen is IF the MPI number typed in response to the parameter query returns a record, then make the "frm ADD TO WARD" visible so it can be used for input; if the query does not return a record, then open "form ADD NEW PATIENT".
What's happening is after entering an MPI number that I know exists, I get "Run-time error '3076': Syntax error (missing operator) in query expression 'MPI='
The code I am using is:
Private Sub AddPatientToWard_Click()
DoCmd.OpenForm "frm ADD TO WARD", , , , , acHidden
If Nz(DLookup("mpi", "qry Add to Ward", "MPI=" & txtMPI), 0) <> 0 Then
Me.Visible = True
Else
DoCmd.Close , "frm ADD TO WARD"
DoCdm.OpenForm "frm ADD NEW PATIENT", , , , , acNormal
End If
End Sub
I have also used the "frm ADD TO WARD" for the domain instead of "qry ADD TO WARD" with the same result.
Thanks again!!
The event procedure opens a form "frm ADD to WARD" in hidden mode, which in turn opens a parameter query "qry ADD to WARD. This query prompts for an ID field value (number field). This ID field is named "MPI".
What I want to happen is IF the MPI number typed in response to the parameter query returns a record, then make the "frm ADD TO WARD" visible so it can be used for input; if the query does not return a record, then open "form ADD NEW PATIENT".
What's happening is after entering an MPI number that I know exists, I get "Run-time error '3076': Syntax error (missing operator) in query expression 'MPI='
The code I am using is:
Private Sub AddPatientToWard_Click()
DoCmd.OpenForm "frm ADD TO WARD", , , , , acHidden
If Nz(DLookup("mpi", "qry Add to Ward", "MPI=" & txtMPI), 0) <> 0 Then
Me.Visible = True
Else
DoCmd.Close , "frm ADD TO WARD"
DoCdm.OpenForm "frm ADD NEW PATIENT", , , , , acNormal
End If
End Sub
I have also used the "frm ADD TO WARD" for the domain instead of "qry ADD TO WARD" with the same result.
Thanks again!!