Problem with Before update

S

scott04

I have the following code in my database:
Private Sub case_no_BeforeUpdate(Cancel As Integer)
If Not IsNull(DLookup("Case_no", "tbllawsuittracking", "Case_no = " &
Me.Case_No)) Then
Cancel = True
MsgBox "This is a duplicate", vbExclamation, "Duplicate value!"
End If
End Sub
Case number is a text field in the tblLawsuitTracking table. What i am
trying to do is prevent a duplicate case number upon entry when entering data
in a form. Problem is I just can't seem to get the code working properly.
Any suggestions on why this isn't working?
 
K

Klatuu

What is the data type of the field Case_no in tbllawsuittracking?
As written, it is expected to be a numeric data type. If it is text, you
need to enclose the compare value in quotes:

If Not IsNull(DLookup("Case_no", "tbllawsuittracking", "Case_no = '" &
Me.Case_No & "'")) Then
 
S

scott04

Dave,
Thank you. It was a text field

Klatuu said:
What is the data type of the field Case_no in tbllawsuittracking?
As written, it is expected to be a numeric data type. If it is text, you
need to enclose the compare value in quotes:

If Not IsNull(DLookup("Case_no", "tbllawsuittracking", "Case_no = '" &
Me.Case_No & "'")) Then
 

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