Problem with Before update

  • Thread starter Thread starter scott04
  • Start date Start date
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?
 
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
 
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
 
Back
Top