BeforeUpdate code not firing

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
 
A

Allen Browne

Since the text box appears to be named "ChildID", try:
intLinkCriteria = "[ChildID]=" & Me.ChildID
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top