Validation Rule DLookup

kstump

New member
Local time
Today, 17:01
Joined
Feb 15, 2005
Messages
8
I have a very simple question . . . This is the first time I have tried to do a DLookup. I have a field CustomerNumber. When the value is entered, I want to make sure this is not a duplicate number in a table LastCustomer. I have been trying to make this work as an AfterUpdate code, but so far it won't work. Could someone give me the code for this? Thank you.
 
Try something like this if the customer number is a text field.
Code:
    If DCount("[CustomerNumber]", "tblCustomers", "[CustomerNumber] = '" & [Forms]![YourForm]!CustomerNumber "'") > 0 Then
        MsgBox "That customer number already exists.", vbInformation, "User ID Already Exists"
        Exit Sub
    Else
        'for testing if false
    End If
 
Last edited:
It didn't work.
The CustomerNumber feild is a number . . . the form name is frmLastCustomer
 
Try this...
Code:
    If DCount("[CustomerNumber]", "YourTableNameHere", "[CustomerNumber] = " & [Forms]![frmLastCustomer]!CustomerNumber") > 0 Then
        MsgBox "That customer number already exists.", vbInformation, "Customer Number Already Exists"
        Exit Sub
    Else
        'for testing if false
    End If
 

Users who are viewing this thread

Back
Top Bottom