Firing an Event on MS Access exit (1 Viewer)

G37Sam

Registered User.
Local time
Today, 11:46
Joined
Apr 23, 2008
Messages
454
Hi,

I would like to know if there's a way one can launch an event when MS Access is closed (hitting the outermost close button)

Regards,
Samer
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 00:46
Joined
Aug 30, 2003
Messages
36,125
One typical method is using the unload event of a form that would always be open. There is no event on the program itself closing.
 

boblarson

Smeghead
Local time
Today, 00:46
Joined
Jan 12, 2001
Messages
32,059
As Paul mentions, I typically will have a hidden form that is open and in its UNLOAD event I will put whatever I want, including code that will ask the user if they really wanted to close the database and setting Cancel = True if they did not, thereby keeping the database open if the close X at the top of the screen was used.
 

aziz rasul

Active member
Local time
Today, 08:46
Joined
Jun 26, 2000
Messages
1,935
On the link above, I get the error

user-defined type not defined on the line

Code:
Dim c As CloseCommand]

when I open my database?
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 00:46
Joined
Aug 30, 2003
Messages
36,125
Never used it, but is that bracket really in your code?
 

pr2-eugin

Super Moderator
Local time
Today, 08:46
Joined
Nov 30, 2011
Messages
8,494
Did you follow the steps correctly?? As the Step 6 says..
On the File menu, click Save (to save the project), and when prompted for the name of the class module, save it as CloseCommand.
So if you save it as such I think the compiler Error will not occur..
 

aziz rasul

Active member
Local time
Today, 08:46
Joined
Jun 26, 2000
Messages
1,935
I checked all that. I now get an error

'the expression you entered has a function name that Microsoft access can't find'

when it runs the InitApplication() function.
 

pr2-eugin

Super Moderator
Local time
Today, 08:46
Joined
Nov 30, 2011
Messages
8,494
So the Function InitApplication() is on a Standard Module, and the other Procedures like Get Enabled() and Let Enabled() are in a separate Class Module?
 

aziz rasul

Active member
Local time
Today, 08:46
Joined
Jun 26, 2000
Messages
1,935
Ah, I had the module types the wrong way round. Thanks.
 

pr2-eugin

Super Moderator
Local time
Today, 08:46
Joined
Nov 30, 2011
Messages
8,494
Yea, I have done something similar to that in the past, so thought it might be case here too.. :D

Good luck.. :)
 

Users who are viewing this thread

Top Bottom