Kashif Naqvi
New member
- Local time
- Today, 15:26
- Joined
- Feb 21, 2021
- Messages
- 1
Need a bit of help in a VBA code that isn't quite working. I am a complete novice- Just using youtube to learn VBA
I am trying to prevent a duplicate entry when one is entering data in a form.
Problem is that the code only reads the first ID but doesn't seem to go down the entire column. Although the duplicate entry doesn't get saved as in the table its indexed to not allow duplicates, but the user has no idea and gets no warning that it was a duplicate entry and hence got rejected.
I am pasting the code below- hope it's understandable. I am not at all a programer- just self learning through youtube videos- now really stuck
Private Sub txtMRID_AfterUpdate()
Dim stLinkCriteria As String
stLinkCriteria = "(txtMRID) =" & "'" & Me.txtMRID.Value & "'"
If Me.txtMRID = DLookup("(MRID)", "tblPatient", stLinkCriteria) Then
MsgBox "This patient has already been entered" _
& vbCr & vbCr & "The e-Log form will now open to input surgical procedure", vbInformation, "Duplicate Entry"
Me.Undo
DoCmd.Close acForm, "frmPatient", acSaveNo
DoCmd.OpenForm "frmWorkLog"
DoCmd.GoToRecord , , acNewRec
End If
End Sub
Thanks a lot
I am trying to prevent a duplicate entry when one is entering data in a form.
Problem is that the code only reads the first ID but doesn't seem to go down the entire column. Although the duplicate entry doesn't get saved as in the table its indexed to not allow duplicates, but the user has no idea and gets no warning that it was a duplicate entry and hence got rejected.
I am pasting the code below- hope it's understandable. I am not at all a programer- just self learning through youtube videos- now really stuck
Private Sub txtMRID_AfterUpdate()
Dim stLinkCriteria As String
stLinkCriteria = "(txtMRID) =" & "'" & Me.txtMRID.Value & "'"
If Me.txtMRID = DLookup("(MRID)", "tblPatient", stLinkCriteria) Then
MsgBox "This patient has already been entered" _
& vbCr & vbCr & "The e-Log form will now open to input surgical procedure", vbInformation, "Duplicate Entry"
Me.Undo
DoCmd.Close acForm, "frmPatient", acSaveNo
DoCmd.OpenForm "frmWorkLog"
DoCmd.GoToRecord , , acNewRec
End If
End Sub
Thanks a lot