Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clearing form with a Cancel button 1

Status
Not open for further replies.

hamzagm

Technical User
Apr 20, 2004
1
0
0
CA
Hi there, I am having a bit of a problem with one of my databases and have tried everything in my knowledge. Perhaps, you can offer me an alternative solution.

I have a basic data entry type form with several fields and two buttons, i.e. CANCEL and SAVE. If at any point, user clicks the CANCEL button, I want to show a message to confirm that this will lose all changes and not save the record. Unfortunately when I hit the Cancel button and if all the required fields are filled in, it saves the record.

I know Access saves records automatically but is there a way to delay this until the user hits the SAVE button???

Any help will be appreciated.
 
Hi Hamzagm

This seems like an overkill to me.

Access has the escape button which (in effect) performs these operations (hit once|twice to undo field|record changes).

If this really doesn't suffice, look into RunCommand|Undo in macros.

If you want to be really professional - look into unbound forms.

Stew



 
Private Sub Closeform_Click()
Hamzagm,

Place a button control on your form then right click on it and select build event. Cut and paste the following code:
______

On Error GoTo Err_closeform_Click

DoCmd.DoMenuItem acFormBar, acEditMenu,acUndo, ,;
acMenuVer70
DoCmd.Close

Exit_Closeform_Click:
Exit Sub

Err_closeform_Click:
MsgBox Err.Description
Resume Exit_Closeform_Click

End Sub
--------------------------

When this is complete, selecting this button will undo your record an close you form. If you just want to undo the record, remove DoCmd.Close. A yes/no message box does seem redundant. If you still want that let me know, and I will send the code.

Chuck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top