Cancel Butten on a Form

G

Guest

Hallo

I hope some one can help me I have a few fields on a form which are linked
to a table. As soon as I enter information into the fields it will enter it
in the table. But what if half way true entering I see I don't want it any
more and delete the complete record. At the moment I know the only way is by
using the ESC key but I would like to have a cancel button that will delete
the record and close the form. If some one could give me the code I would be
very happy.

Thank you

Markus.
 
A

Allen Browne

The code for the event procedure of your command button to cancel the entry
and close the form would look something like this:

Private Sub cmdCancelClose_Click()
If Me.Dirty Then
Me.Undo
End If
DoCmd.Close acForm, Me.Name
End Sub

Note that Access will run the code to validate the control that has focus
before it lets the command button take focus. If you are part-way through
entering a date - say, 2/1/ - Access won't accept that invalid entry, and so
the command button won't accept focus until it's fixed. It may therefore be
better to use an undo button on a toolbar than a command button on the form.
 

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

Similar Threads


Top