problems closing form

  • Thread starter Thread starter L Melville
  • Start date Start date
L

L Melville

Hi,

I have several forms that refuse to close, I have 2 buttons on each form (a
cancel button and a save and close button) the cancel button simply calls
DoCmd.Close, and the save button does some processing and then calls
DoCmd.Close, the save button however does not close the form, the processing
before the DoCmd.Close is called generates no errors and I can pop a msgbox
up right before the DoCmd.Close, but it does not work. I have done something
similar which works perfectly but on these forms it isn't working, has
anyone got any ideas?

thanks in advance
lee
 
Lee

Have you got any code in the Form's UnLoad event where the Cancel parameter
is being set True?

Andy
 
actually yes, I have some code that updates a listview control on another
form, I have moved this (ie emptied the unload event) and its now working, I
also had some code tat removed the form from a collection as the form can be
opened many times simultaneously, why is it that this has affected the
closing of the for though, I am a bit puzzled?

lee
 
The unload event is run *before* the Form actually closes. In a Bound form
the Unload is where the form is disconnected from its record source. If the
Cancel parameter is set True in this event, the Unload event is cancelled
which means that the Close event is also prevented.


Private Sub Form_Unload(Cancel As Integer)

......do some code
Cancel = True
.....may some more code

End Sub

If Cancel is *not* set true (or is set False), the unload event should *not*
be cancelled and the form should close as normal.

HTH

Andy
 
Back
Top