catch matching field error

spinkung

Registered User.
Local time
Today, 04:17
Joined
Dec 4, 2006
Messages
267
Hi

i have a subform which is linked to a people table. when i start entering a new record sometimes i want to exit without saveing but when i click of the record i get an error message ....

The Microsoft Access database engine cannot find a record in the table [TableName] with key matching field(s) [PrimaryKeyFieldName]

is there an event i can catch to roll back/delete the new record?

thanks
 
I use ac2003 and use a command undo button :

Private Sub Command671_Click()
On Error GoTo Err_Command671_Click

DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
Exit_Command671_Click:
Err_Command671_Click:
MsgBox Err.Description
Resume Exit_Command671_Click

End Sub

This is the basic undo and does not close the record , you would have to enter the command code for closing your current form .

You could improve it by adding a vbOK With a msg "Are you sure you wish to exit without saving.

Note if you are using autonumbers the new number generated will be deleted from the table but not from the auto number sequence so that number is lost . hope that makes sense.?
 
Actually, in the subform's BEFORE UPDATE event, do a check using a DCount to find out if there is a matching record and, if not issue a

Cancel = True

and also

Me.Undo

@ypma - You should avoid using DoMenuItems. Those are not easily determined as to what they are and only exist for backwards compatibility. Use the newer
DoCmd.RunCommand acCmdxxxxxxx commands instead.
 
@Boblarson Thank you for that advice i will take it on board and use it in the future.
 
thanks both

i will try these out and let you know how it goes
 

Users who are viewing this thread

Back
Top Bottom