If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Problem with Before update
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? |
#2
|
|||
|
|||
Problem with Before update
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 Hargis, Microsoft Access MVP "scott04" wrote: 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? |
#3
|
|||
|
|||
Problem with Before update
Dave,
Thank you. It was a text field "Klatuu" wrote: 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 Hargis, Microsoft Access MVP "scott04" wrote: 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? |
Thread Tools | |
Display Modes | |
|
|