C
coachjeffery
I have a form EP Data which has a bound text box PatientID (number, indexed).
All of the data is stored in the Patients table. When the user keys in the
PatientID number i want the BeforeUpdate event to search the Patient table
for an existing record, if found, ask if they want to edit the record or key
in a new PatientID number. If they want to edit the existing record, i want
it to open that record. The form also has a sub form EP Data subform.
Here is the code i have so far based on what i have gathered from other
posts to this site.
Private Sub PatientID_BeforeUpdate(Cancel As Integer)
If Not IsNull(DLookup("PatientID", "Patients", "PatientID=" &
PatientID.Value)) Then
Cancel = (MsgBox("A record exists for this PatientID, do you want to
edit the record?", vbQuestion + vbYesNo) = vbNo)
End If
End Sub
If I click No, it sets the focus back to the PatientID field which is what i
want. If I ckick yes, It does open the related subform but I get an error
"The changes to the table were not successful because it would create
duplicate values..."
Any thoughts on what i am missing? Thanks in advance for the assistance.
All of the data is stored in the Patients table. When the user keys in the
PatientID number i want the BeforeUpdate event to search the Patient table
for an existing record, if found, ask if they want to edit the record or key
in a new PatientID number. If they want to edit the existing record, i want
it to open that record. The form also has a sub form EP Data subform.
Here is the code i have so far based on what i have gathered from other
posts to this site.
Private Sub PatientID_BeforeUpdate(Cancel As Integer)
If Not IsNull(DLookup("PatientID", "Patients", "PatientID=" &
PatientID.Value)) Then
Cancel = (MsgBox("A record exists for this PatientID, do you want to
edit the record?", vbQuestion + vbYesNo) = vbNo)
End If
End Sub
If I click No, it sets the focus back to the PatientID field which is what i
want. If I ckick yes, It does open the related subform but I get an error
"The changes to the table were not successful because it would create
duplicate values..."
Any thoughts on what i am missing? Thanks in advance for the assistance.