can't trap form_close /unload event?

F

faz

hello
i want that a form close itself when the user press a commandbutton, and
before that
some controls has to be executed. The problem is that vba shows no errors
but
the form can't close itself unless user press X in the top-right corner

here my simple code
------------------------------------------------
Option Compare Database

Private Sub cmdok_Click()
On Error GoTo Err_handler

Form_Unload (False)
exit sub

Err_handler:
Debug.Print "Errore:"; Err.Description; Err.Number

End Sub

Private Sub check_routine1()

Debug.Print "dentro check_routine"

End Sub

Private Sub Form_Unload(Cancel As Integer)
check_routine1

end sub
-----------------------------------------------------

if i switch form_unload with form_close event nothing changes, and if i add
a docmd.close command at the end of the event handler an error will raise

Thanks for any help
 
A

Arvin Meyer [MVP]

Your code tells the form not to close. The following line stops it from
closing:

Form_Unload (False)

I'm not sure what you are trying to accomplish, but canceling the Unload
event won't do it.
 
F

faz

Arvin Meyer said:
Your code tells the form not to close. The following line stops it from
closing:

Form_Unload (False)

Not true, and if i do with true, same result: the form won't close. And i
tried to call
form_close() too but form won't close

I'm not sure what you are trying to accomplish

A very simple task: the user press a button, then a routine is called and
the form has to close. Problem is form won't close. It close only if user
press X(or alt+f4), but i want to do it with a button
 
J

John Spencer

Docmd.Close acForm, "NameOfForm"

If you are running the code in the form's module you can use
Docmd.Close acForm, Me.Name

Or even use
Docmd.Close acForm
If you want to gamble on the form with the focus is the one you want to close.

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
 
F

faz

John Spencer said:
Docmd.Close acForm, "NameOfForm"

If you are running the code in the form's module you can use
Docmd.Close acForm, Me.Name

Or even use
Docmd.Close acForm
If you want to gamble on the form with the focus is the one you want to
close.

Thank you, it works
so i guess calling directly for an event doesn't work on vba
 
D

Dirk Goldgar

faz said:
Thank you, it works
so i guess calling directly for an event doesn't work on vba


Calling an event procedure does not make the event happen -- not in any
language with which I am familiar.
 
F

faz

Dirk Goldgar said:
Calling an event procedure does not make the event happen -- not in any
language with which I am familiar.

you're right ,it's pretty logical too
 

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