need form unload procedure

D

dp

Hi everyone,

I am trying to set some conditions in my form unload procedure in case a
user tries to close the form before some validation is performed.
(closingprocures is a function which validates)

Here is my code:

DoCmd.CancelEvent
If (ClosingProcedures = False) Then
Exit Sub
Else
DoCmd.Close acForm, Me.Name
End If

So, what happens is the form closes, which it shouldn't
then it gives me an error at the close form line, error 2501, The close
action was cancelled.

Does anyone know how to accomplish this?

Thanks in advanced,
 
A

Andi Mayer

Hi everyone,

I am trying to set some conditions in my form unload procedure in case a
user tries to close the form before some validation is performed.
(closingprocures is a function which validates)

Here is my code:

DoCmd.CancelEvent
If (ClosingProcedures = False) Then
Exit Sub
Else
DoCmd.Close acForm, Me.Name
End If

So, what happens is the form closes, which it shouldn't
then it gives me an error at the close form line, error 2501, The close
action was cancelled.

Does anyone know how to accomplish this?

Thanks in advanced,

after the doCmd.close you have to Exit Sub

otherwise the code is still running, but the FormObject is deleted
 
D

dp

Hi Andy,

Thanks for quick response.

I tried your solution and that did not help. I received the same error.

Any suggestions?

Thanks so much,
D
 
Top