G
Guest
I’m using BeforeUpdate code in a text field with Number data type to prevent
duplicate entries. However, the code doesn’t fire when a duplicate entry is
entered. When the user leaves the field, instead of getting prompted, nothing
happens - no error message, no anything. The code (with some small minor
changes) works fine in another database where the field is a text field with
Text data type, so I assume the problem is related to the fact that the field
I'm trying to evaluate is a Number data type. Any ideas? Thanks. - Kurt
###
Private Sub ChildID_BeforeUpdate(Cancel As Integer)
Dim CID As Integer
Dim intLinkCriteria As Integer
Dim rsc As DAO.Recordset
Set rsc = Me.RecordsetClone
CID = Me.ChildID.Value
intLinkCriteria = "[ChildID]=" & CID
'Check table for duplicate Child ID
If DCount("ChildID", "tblPatient", intLinkCriteria) > 0 Then
'Undo duplicate entry
Me.Undo
'Message box warning of duplication
MsgBox "A Child ID of " _
& CID & " has already been entered." & _
Chr(13) & Chr(13) & "Please check to see if this child has already
been entered. " & _
"If not, then assign it a different ID.", vbInformation, "Duplicate
Information"
End If
Set rsc = Nothing
End Sub
duplicate entries. However, the code doesn’t fire when a duplicate entry is
entered. When the user leaves the field, instead of getting prompted, nothing
happens - no error message, no anything. The code (with some small minor
changes) works fine in another database where the field is a text field with
Text data type, so I assume the problem is related to the fact that the field
I'm trying to evaluate is a Number data type. Any ideas? Thanks. - Kurt
###
Private Sub ChildID_BeforeUpdate(Cancel As Integer)
Dim CID As Integer
Dim intLinkCriteria As Integer
Dim rsc As DAO.Recordset
Set rsc = Me.RecordsetClone
CID = Me.ChildID.Value
intLinkCriteria = "[ChildID]=" & CID
'Check table for duplicate Child ID
If DCount("ChildID", "tblPatient", intLinkCriteria) > 0 Then
'Undo duplicate entry
Me.Undo
'Message box warning of duplication
MsgBox "A Child ID of " _
& CID & " has already been entered." & _
Chr(13) & Chr(13) & "Please check to see if this child has already
been entered. " & _
"If not, then assign it a different ID.", vbInformation, "Duplicate
Information"
End If
Set rsc = Nothing
End Sub