close button does not detect duplicate

laurat

Registered User.
Local time
Today, 05:29
Joined
Mar 21, 2002
Messages
120
On a form users enter records into I have created a close button and placed it on the form. The problem is that when a duplicate number is entered in the primary key field and the close button I have created is used, no error message of a duplicate record is given. The form just closes and the record is not saved. When the 'X' in the upper right corner is used to close the form it tells the user that a duplicate value has been entered in the primary key field.

Is there a way to correct this problem with the close button I have created? Add code or another solution??
 
try entering the save command before the close command

DoCmd.RunCommand acCmdSave
 
Failing that, the other method is in the Form_BeforeUpdate routine, you can do a DCount( "[NumberField]", "MyTable", "[NumberField]=" [NumberOnForm] )

If the DCount is > 0 you have a duplicate, in which case you want to cancel the Update event.
 

Users who are viewing this thread

Back
Top Bottom