Closing Access 2003 Programatically

G

Guest

I have a routine that is run when exiting my application. The routine works
fine when exiting the application via a custom 'exit' menu option, but it is
not called if the user simply clicks on the cross (X) instead.

Is there any way to call an event procedure when closing an Access 2003 mde
application in this way?

Any help or useful links are much appreciated.

Regards

Byz
 
S

Steve Huff

What I do is just disable the (X) so they can not close the database that
way. Below is the code you need. Simply call NoX on startup of the
database.

Const MF_BYPOSITION = &H400
Private Declare Function GetSystemMenu Lib "User32" _
(ByVal hWnd As Long, ByVal bRevert _
As Long) As Long

Private Declare Function RemoveMenu Lib "User32" _
(ByVal hMenu As Long, ByVal nPosition _
As Long, ByVal wFlags As Long) As Long

Public Sub NoX()
RemoveMenu GetSystemMenu(Application.hWndAccessApp, 0), 6, MF_BYPOSITION
End Sub
 
L

Lynn Trapp

In addition to what Steve said, you can put your routine (or a call to it)
in a form that you open, in invisible mode, when your database opens.
Anytime the database closes, regardless of how it is closed, the form will
have to be closed first and, thus, your routine will run.
 

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