Cancelling the close form statement.

G

Guest

I have an EditRecord form that detects if changes have been made to the
record on the form. I have two buttons; cmdsave and cmdclose. When I click
cmdsave everything is saved perfectly. When I click cmdclose I am prompted,
if changes have been made, to save the changes. Code on cmdClose is:
DoCmd.Close acForm, "Frm_EditBooking", acSaveNo
On the form unload event I have:
If fDataChanged Then

Select Case MsgBox("Do you want to save changes?", vbYesNoCancel)
Case vbYes '*****Problem occurs when this criteria is true****
cmdSave_Click
Exit Sub
Case vbNo
'do nothing
Case vbCancel
Cancel = True
Exit Sub
End Select
End If

cmdSave_click gets to the line:
DoCmd.Close acForm, "Frm_EditBooking", acSaveYes
Then detects an error displaying "The close action was cancelled" Is this
because the form is attempting to close twice? I can't work it out! Can
someone please help!!
Thanks
 
J

Jeff Boyce

Greg

It appears you are waiting until the form unload event to test for changes
and save. What happens if you move this process/code up earlier, say, in
the form's Close event?

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
G

Guest

First, the close event can't be canceled
Next, the Unload event happens prior to the close. Here is the order of
events:

Unload → Deactivate → Close

The question is what happens in cmdSave_Click?
Also, is this a bound or unbound form?
If it is a bound form, nothing would be required if Save were selected.
Closing the form updates the record. If you don't want to safe the record,
the Me.Undo would cause the record not to be saved.
 
G

Guest

Jeff, Knowing the order of events changes everything. My code is written
assuming close occurs before unload. A few changes required!! Thanks for your
help.
 

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