On error cancel event (1 Viewer)

Matizo

Registered User.
Local time
Yesterday, 16:10
Joined
Oct 12, 2006
Messages
83
Hi,

Quick question..

What code should there be between DoCmd.RunCommand acCmdDeleteRecord AND DoCmd.Close
If I don't enter any data I get a msg "Record cannot be deleted at this time.."
so I need a code that on error would cancel the event and carried on with closing the form.

This is the whole code:

Private Sub Exit_Click()
On Error GoTo Err_Exit_Click


DoCmd.RunCommand acCmdDeleteRecord
DoCmd.Close

Exit_Exit_Click:
Exit Sub

Err_Exit_Click:
MsgBox Err.Description
Resume Exit_Exit_Click

End Sub


Thanks!
 

JohnLee

Registered User.
Local time
Yesterday, 16:10
Joined
Mar 8, 2007
Messages
692
Hi

Try this:

Private Sub Exit_Click()
On Error Resume Next



DoCmd.RunCommand acCmdDeleteRecord
DoCmd.Close

Exit_Exit_Click:
Exit Sub


End Sub


JOHN
 

Matizo

Registered User.
Local time
Yesterday, 16:10
Joined
Oct 12, 2006
Messages
83
Hi John,

It work perfectly,

Thanks!
 

JohnLee

Registered User.
Local time
Yesterday, 16:10
Joined
Mar 8, 2007
Messages
692
Hi Matizo,

Glad to have been of help.

John
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 00:10
Joined
Sep 12, 2006
Messages
15,749
the trouble is that if you do that, the delete may or may not take place, and you dont know which - which can prove problematical.
 

Users who are viewing this thread

Top Bottom