DoCmd Open Form question

  • Thread starter Thread starter Saul
  • Start date Start date
S

Saul

I am creating a database with clients identified by a
client ID number (MRN). To view/enter data for a
particular client the user types in the client's MRN and
clicks "OK" which runs the following code created by the
wizard:

Private Sub cmdOpenfrmClientConfirm_Click()
On Error GoTo Err_cmdOpenfrmClientConfirm_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmClientConf"

stLinkCriteria = "[MRN]=" & "'" & Me![MRN] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_cmdOpenfrmClientConfirm_Click:
Exit Sub

Err_cmdOpenfrmClientConfirm_Click:
MsgBox Err.Description
Resume Exit_cmdOpenfrmClientConfirm_Click

End Sub

If the client has not yet been entered into the database
(i.e., that MRN does not exit in the client table), the
code as written opens frmClientConfirm which is blank.
Instead, if the client is not yet in the database, I would
like to interrupt the code and display a message box
saying "this client has not yet been entered into the
database..." and ultimately direct the user to a form
designed to enter a new client into the database. What is
the best way to accomplish this. Thanks for your help.

Sual
 
tr

Private Sub cmdOpenfrmClientConfirm_Click(
On Error GoTo Err_cmdOpenfrmClientConfirm_Clic

Dim stDocName As Strin
Dim stLinkCriteria As Strin

stDocName = "frmClientConf
if mrn.value="" the
msgbox "this client has not yet been entered into the
database...
exit su
end i

stLinkCriteria = "[MRN]=" & "'" & Me![MRN] & "'
DoCmd.OpenForm stDocName, , , stLinkCriteri

Exit_cmdOpenfrmClientConfirm_Click
Exit Su

Err_cmdOpenfrmClientConfirm_Click
MsgBox Err.Descriptio
Resume Exit_cmdOpenfrmClientConfirm_Clic

End Su
 
If DCount("*", "tblClientConf", stLinkCriteria ) > 0 then

DoCmd.OpenForm stDocName, , , stLinkCriteria

Else
DoCmd.OpenForm stDocName, , , , acFormAdd

End If
 
Back
Top