The code should first make sure that the number is in the table and then if it is, open form 2 (Time Data) from which the user can proceed. If it is not in the table then the user can simply complete the data on the original form. When a new patient is added the table should requery upon close as well as leave the "PatientMRN" field blank and ready to continue.
To this end I have inserted the following code:
Code:
Private Sub PatientMRN_AfterUpdate()
On Error GoTo Err_Command17_Click
Dim Answer As Integer
Answer = MsgBox("Do you want to readmit this MRN?", vbYesNo, "Patient MRN")
'Make a decision based on button user clicked.
If Answer = vbYes Then
'Code to execute Open Readmit Form.
DoCmd.OpenForm "Time Data", acNormal, , , acFormAdd, acWindowNormal
Else
'Code to execute if user clicks on No.
If Null Then
DoCmd.Close , "Time Data", acSaveNo
End If
End If
Exit_Command17_Click:
Exit Sub
Err_Command17_Click:
MsgBox Err.Description
PatientMRN.SetFocus
Resume Exit_Command17_Click
End Sub
It works for getting to the second form (Time Data) when the user selects "Yes". But, at the same time form 2 (Time Data) opens the user gets the standard message about the number already being in the system and must click "OK". As the user selects "Yes" a new record is added to the original table with no data at all.
When "No" is selected the new number should left (in effect saying that the new number is not in the table) in the "PatientMRN" field and set focus to the next field allowing the user to complete adding data to the original form and then save the new patient data to the table.
Thanx for the help.