I'm new to programming and this forum, but it appears that people are willing to help newbies like me so I thought I'd give it a try.
I have 2 forms, the first is to enter a patient number, if it exists in the table, I want to open to the record, if not, I want to open the form to a new record. New records are not a problem. However, the second form does not load the record specified in the OpenForm criteria. The DCount works correctly for single and multiple field criteria.
I actually have a few pairs of these. On one form, it loads blank, on another it opens to the first record.
The strangest part is that I had this working yesterday afternoon, somehow broke it, fixed it today and just broke it again. Is there something outside my code that the form is looking to when it opens?
Thanks for any help!
Private Sub cmdEnter_Click()
If DCount("[PtID]", "tblPatients", "[PtID]='" & Me!enterPtID & "'") > 0 Then
MsgBox "Patient already in database." & vbCrLf & vbCrLf & "Please verify Data."
DoCmd.OpenForm "frmPatients", , , "[PtID]='" & Me!enterPtID & "'"
Else: MsgBox "Enter new patient Data"
DoCmd.OpenForm "frmPatients", , , , acFormAdd
Forms!frmPatients!txtPtID.Value = Forms!EnterPatient!enterPtID
End If
DoCmd.Close acForm, "EnterPatient"
End Sub
I have 2 forms, the first is to enter a patient number, if it exists in the table, I want to open to the record, if not, I want to open the form to a new record. New records are not a problem. However, the second form does not load the record specified in the OpenForm criteria. The DCount works correctly for single and multiple field criteria.
I actually have a few pairs of these. On one form, it loads blank, on another it opens to the first record.
The strangest part is that I had this working yesterday afternoon, somehow broke it, fixed it today and just broke it again. Is there something outside my code that the form is looking to when it opens?
Thanks for any help!
Private Sub cmdEnter_Click()
If DCount("[PtID]", "tblPatients", "[PtID]='" & Me!enterPtID & "'") > 0 Then
MsgBox "Patient already in database." & vbCrLf & vbCrLf & "Please verify Data."
DoCmd.OpenForm "frmPatients", , , "[PtID]='" & Me!enterPtID & "'"
Else: MsgBox "Enter new patient Data"
DoCmd.OpenForm "frmPatients", , , , acFormAdd
Forms!frmPatients!txtPtID.Value = Forms!EnterPatient!enterPtID
End If
DoCmd.Close acForm, "EnterPatient"
End Sub