S
Sandy Burgess
I am really struggling with an input form for new patients. Input form
should NOT allow duplicate SSN's.
Table called patient data contains SSN (text Field). There is also a field
called ID that is numeric. I have the following event procedure coded to the
before update .
Code 1:
Private Sub textSSN_BeforeUpdate(Cancel As Integer)
Dim strCriteria As String
strCriteria = "[SSN] = '" & Me.textSSN & "' AND " _
& "[ID] <> " & Me.textID
If IsNull(DLookup("SSN", "Patient Data", strCriteria)) Then
'do nothing, no match
Else
MsgBox "SSN exists. Verify SSN."
Cancel = True
Me.textSSN.SelStart = 0
Me.textSSN.SelLength = Len(Me.textSSN)
End If
End Sub
When a duplicate SSN is entered on the form I get the msg box with "SSN
exists. Verify SSN". When I hit ok. I get an Access Popup that states “The
value in the field or record violates the validation rule for the record or
field ………â€
How can I get rid this second popup?
I have also tried Code 2 which gives me the same result. Code 2 is
Private Sub textSSN_BeforeUpdate(Cancel As Integer)
Dim strCriteria As String
strCriteria = "[SSN] = '" & Me.textSSN & "' AND " _
& "[ID] <> " & Me.textID
If IsNull(DLookup("SSN", "Patient Data", strCriteria)) Then
'do nothing, no match
Else
MsgBox "SSN exists. Verify SSN."
Cancel = True
Me.textSSN.Undo
End If
End Sub
Never fear, I went out on a limb and tried code 3 which gives me the same
result. Code 3 is
Private Sub textSSN_BeforeUpdate(Cancel As Integer)
Dim strCriteria As String
strCriteria = "[SSN] = '" & Me.textSSN & "' AND " _
& "[ID] <> " & Me.textID
If IsNull(DLookup("SSN", "Patient Data", strCriteria)) Then
'do nothing, no match
Else
MsgBox "SSN exists. Verify SSN."
Cancel = True
Me.textSSN.Undo
End If
End Sub
I am a self taught access person. Never learned how to code. Can someone
help me? This is a volunteer project for a health free clinic. Your help is
appreciated
Sandy Burgess
should NOT allow duplicate SSN's.
Table called patient data contains SSN (text Field). There is also a field
called ID that is numeric. I have the following event procedure coded to the
before update .
Code 1:
Private Sub textSSN_BeforeUpdate(Cancel As Integer)
Dim strCriteria As String
strCriteria = "[SSN] = '" & Me.textSSN & "' AND " _
& "[ID] <> " & Me.textID
If IsNull(DLookup("SSN", "Patient Data", strCriteria)) Then
'do nothing, no match
Else
MsgBox "SSN exists. Verify SSN."
Cancel = True
Me.textSSN.SelStart = 0
Me.textSSN.SelLength = Len(Me.textSSN)
End If
End Sub
When a duplicate SSN is entered on the form I get the msg box with "SSN
exists. Verify SSN". When I hit ok. I get an Access Popup that states “The
value in the field or record violates the validation rule for the record or
field ………â€
How can I get rid this second popup?
I have also tried Code 2 which gives me the same result. Code 2 is
Private Sub textSSN_BeforeUpdate(Cancel As Integer)
Dim strCriteria As String
strCriteria = "[SSN] = '" & Me.textSSN & "' AND " _
& "[ID] <> " & Me.textID
If IsNull(DLookup("SSN", "Patient Data", strCriteria)) Then
'do nothing, no match
Else
MsgBox "SSN exists. Verify SSN."
Cancel = True
Me.textSSN.Undo
End If
End Sub
Never fear, I went out on a limb and tried code 3 which gives me the same
result. Code 3 is
Private Sub textSSN_BeforeUpdate(Cancel As Integer)
Dim strCriteria As String
strCriteria = "[SSN] = '" & Me.textSSN & "' AND " _
& "[ID] <> " & Me.textID
If IsNull(DLookup("SSN", "Patient Data", strCriteria)) Then
'do nothing, no match
Else
MsgBox "SSN exists. Verify SSN."
Cancel = True
Me.textSSN.Undo
End If
End Sub
I am a self taught access person. Never learned how to code. Can someone
help me? This is a volunteer project for a health free clinic. Your help is
appreciated
Sandy Burgess