cancel button to undo data entry

J

Julie

I have a form set up for data entry. I want to have a cancel button on the
form that will close the form without saving any data, should the user decide
that's what needs to happen.

Right now, I have this:

Private Sub Cancel_Click()
DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
DoCmd.OpenForm "Switchboard", acNormal, "", "", , acWindowNormal
DoCmd.Close acForm, "EnterNewParticipant"
End Sub

This works if the user has started entering data. However, if the user
enters the form, doesn't type anything, and clicks the cancel button, I get
an error "The command or action 'Undo' isn't available now." What do I have
to do to avoid the error but still achieve the results I'm getting above?
 
L

Linq Adams via AccessMonster.com

Private Sub Cancel_Click()
If Me.Dirty Then
DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70
End If

DoCmd.OpenForm "Switchboard", acNormal, "", "", , acWindowNormal
DoCmd.Close acForm, "EnterNewParticipant"
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top