Check for duplicate and error message

casper

Registered User.
Local time
Today, 07:56
Joined
Aug 26, 2006
Messages
12
I have a form - see attached image.
The first text box is called Job_No. When a number is entered here how can I check that the number doesn't already exist when the user tabs to the next box. Then if it does exist display a custom message to the effect "This already exists" and not the Access default duplicate error message.

Thanks

Michael
 

Attachments

  • Form.jpg
    Form.jpg
    76.6 KB · Views: 164
In the field's OnLoseFocus or AfterUpdate event, or in the form's BeforeUpdate event, you could use the DCount() function to see if there is at least one record present. e.g. something like
Code:
If DCount("JobNumber","JobTable","JobNumber = " & [Forms]![[I]formname[/I]]![Job_No]) Then
     Msgbox "That Job Number already exists"
     [Forms]![[I]formname[/I]]![Job_No] = ""
     [Forms]![[I]formname[/I]]![Job_No].SetFocus
End If
 

Users who are viewing this thread

Back
Top Bottom