Delete and Cancel buttons

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I thought I had this down but these two buttons do not work on my form.

I want to have a delete button that deletes what the user has entered.
Ideally I would like it to delete the record and have a message box that says
"you have deleted this record".

I also need a cancel button that is different from a close button. I'm
thinking that this would cancel the users progress and close out the form???

Coding and steps would be great. Thank you thank you thank you!
 
To clear the form, just use this code in the Click event procedure of your
button:
If Me.Dirty Then Me.Undo
If it was a new record, it will return the user to the virgin screen. If it
was an existing record, it will return the record to how it was.

For a cancel button, you need that line and one to close the form:
If Me.Dirty Then Me.Undo
DoCmd.Close acForm, Me.Name

Note that the user will not be able to get to those buttons if they are
part-way through entering a value in a text box. For example, if they are in
a Date field, and have typed:
2/2/
that's not a valid date entry, and Access will not let them out of the text
box to click the button. They therefore have to press Esc to undo the entry,
or complete the entry of the field before they can click your button.

For that reason, it is better to use buttons on the toolbar rather than
buttons on the form. There is already an Undo button on the toolbar that
does not have this problem, and there is an X on the right-end of the form's
Title bar for closing the form.
 
Back
Top