Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I detect if the user had quit Access using VBA code 2

Status
Not open for further replies.

maupiti

Programmer
Oct 27, 2003
240
US
Access 2003

When a user quit Access in my database, he can click on the button "quit" that has a code "DoCmd.Quit". If this button is clicked, then I can have access perform a calculation of
A = B + 1.

////////////////////////////////////

Private Sub QUIT_Click()
A = B + 1
DoCmd.Quit
End Sub

///////////////////////////////////

If the user just happend to click on an X-box on the upper right hand corner of Access to quit the application, then how would I trap this event so that I can have Access perform the calculation of A = B + 1 ?
 
you can't because the close at the upper right corner doesn't have a accessable event.

however you can disable the x with a few api calls...

there's already some code on this site for that...

--------------------
Procrastinate Now!
 
Or you could create a hidden form that loads when the database does and call your procedure on that form's [tt]Unload()[/tt] or [tt]Close()[/tt] event.

Hope this helps,
CMP

(GMT-07:00) Mountain Time (US & Canada)
 
Hi Crowley16, and thank you for responding. Can you show me the link so I could obtain this code ?
 
CautionMP's solution would be better as it catches almost all the non-crashing ways of exiting a db...

--------------------
Procrastinate Now!
 
Hi CautionMP.
1) How do you make a form hidden ?
2) You said this hidden form will load when Access is
activated. The hidden form have code
in the Unload or Close Event, but how does this code
gets activated if the user click on the X-box in
the upper right hand corner ?
 
[ol][li]Create a new form.[/li][li]Add the code you want to run when the database closes to the [tt]Close()[/tt] event: (i.e.)
Code:
Private Sub Form_Close()
  MsgBox "The hidden form is being closed."
End Sub
[/li][li]Save the form.[/li][li]Create a new macro and add the OpenForm action with the following arguments:[ul][li]Form Name: the name of the form you just created[/li][li]View: Form[/li][li]Window Mode: Hidden[/li][/ul][/li][li]Save the macro as Autoexec[/li][/ol]

This will load the form hidden automatically when the database opens, when the database closes (normally) the hidden form will be closed first causing the code in the [tt]Close()[/tt] event to fire, in this example a Message Box telling you 'The hidden form is being closed.'.

Note: If Access exits abnormally this event will not fire and if the user presses the shift key while the database is being opened the Autoexec macro will not fire.

Hope this helps,
CMP

(GMT-07:00) Mountain Time (US & Canada)
 
Hi Crowley16. I still want to see the API code to disable the X-Box on the upper right-hand corner of the Access database window. Please give me give me the link.
 
Er, eh, Search?

Right next to Forum at the top of the page.

(GMT-07:00) Mountain Time (US & Canada)
 
Hi CautionMP.

I know where it is, but what is the keyword ?
I did use "disable x-box in Access" and several other text combination but I did not find any.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top