Access Close Button: Event

J

Jess

I have a form and a subform.

When I click somewhere on the subform and then on the access close button,
the subform exit event seems to fire first –I am probably wrong on this.

Is there an event firing right after I click on the access close button and
before the subform exit event fires?

Thanks
 
D

Dale_Fye via AccessMonster.com

Probably the BeforeUpdate event of either the form or subform.

I don't allow the users to close my applications using the Access close
button (X).

Instead, I set the Control Box, Control Buttons properties to No and put a
command button for closing the form on each form. I then add code similar to
the following inside the forms code module:

1. In the declarations section I use: Public AllowClose as boolean

2. In the forms Load event, I add: AllowClose = False

3. In the forms Unload event, I do:

Private Sub Form_Unload(Cancel As Integer)

Cancel = iif(AllowClose = true, False, True)
if Cancel = true then
msgbox "Use the 'Close' button to close this form
me.visible = true
endif

End Sub

4. Finally, in the Click event of the Close button, I use:

Private Sub cmd_Close_Click

AllowClose = true
docmd.close acform, me.name

End Sub

I generally create a form template that has all of this code, as well as the
defaults (font, font size, colors, navigation buttons, ...) for all of my
form controls. Then, whenever I need a new form, I open the frm_template and
save it with the appropriate name.

HTH
 
J

Jack Leach

Subforms and their parents will automatically save when the focus is switched
between the two. When you hit the close button, the focus is going to the
main form, in which case the update events of the subform will fire if it is
dirty. Come to think of it, any LostFocus or Exit (is this for forms or only
certain controls?? not sure..) events may run during this time as well.

hth
--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 

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