Cancel Save On Close

S

Samantha

Hi
I'm trying to cancel all/any changes or additions made on the form when the
form is closed (ie, the user close on the form without clicking on the
'Cancel' button on the form), by clicking on the top right 'X' of the form.
This form is basicaly a data entry form.
I added the following codes to the OnClose and OnUnload events but it does
not work:
if me.dirty then me.undo

Is there any way to 'undo' any changes prior to the form's complete close?
 
J

Jeanette Cunningham

Samantha,
Instead of doing it this way, you can set the data entry property of the
form to read only. This stops users making any changes to data - which
sounds like what you are asking for.
On the form's property sheet | Data tab
Allow Edits = No
Data Entry = No
Allow Additions = No

Another approach is to leave the form able to be edited, but lock each
control where the user could enter data.

A third approach is to open the form using the acDialog argument in the
DoCmd.OpenForm
Check vba help on OpenForm for details of this.
 
D

Dale Fye

Sam,

The way I prevent this is to declare a private variable (AllowClose as
boolean) in the declarations section of the forms code module.

Then, in the forms Open event, I set AllowClose = False

Then, in the Cancel and Save command buttons Click events, I set AllowClose
= True.

Finally, in the Forms Unload event, I test to see whether AllowClose is
False, if not I display a message and cancel the unload event.

Private Sub Form_Unload(Cancel as integer)

If AllowClose = False then
msgbox "Click the Cancel or Save button to close this form!"
Cancel = true
endif

End sub


HTH
Dale
 
T

TulsaPilot

Are you making changes to the data or changes to the form? If it's the
later, this is the same issue I've been trying to tackle. If I get an answer
I'll post it here. See my post from today (Apr 29th).
 

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