Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create Error Message when adding new record

Status
Not open for further replies.

Melee

Programmer
Jun 20, 2000
50
US
I have a macro for the menu bar that opens a form to add a new record. The record name property allows No Duplicates. I need an error message to appear if the new record entered has the same name as an existing one.

Currently, the form appears to accept data changes, but does not. This needs to happen as soon as the duplicate name is entered.

How can I do this easily?
 
Have you set the field that you do not want duplicated as either the form's underlying table's primary key or to Indexed with No Duplicates allowed (either one has to be set)? If so then do the following.
On the On_Error() event of your data entry form, type the following code;

If (DataErr = 3022) Then
MsgBox " duplicate data entry etc etc..."
If Me.Dirty Then Me.Undo 'if record modification was attempted, undo changes.
Response = acDataErrContinue
End If


note: DataErr # 3022 is Access's error num for duplicate record entry.
 
Yes, The record is the key field. I will give it a try. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top