need form unload procedure

G

Guest

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
 
G

Guest

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
 

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