Calling a Function on App Exit - No matter which method is used to exit 
Author Message
 Calling a Function on App Exit - No matter which method is used to exit

Hi.

I have a function in my app called LOGOFF which records some information,
for auditing purposes in my system.  I want to call this function not only
when the user clicks 'Logoff', or chooses 'Exit', but also when they use the
X button in the upper right corner, or whenever the program generates a
run-time error and cannot continue.  The latter example may not be possible,
since the 'program cannot continue', but I'm looking for the best solution
to call this function whenever my app exits, regardless of the method by
which it exits.  Any help would be greatly appreciated.

Thanks!
Brad



Sun, 01 May 2005 07:31:45 GMT  
 Calling a Function on App Exit - No matter which method is used to exit

Quote:
> Hi.

> I have a function in my app called LOGOFF which records some
> information, for auditing purposes in my system.  I want to call this
> function not only when the user clicks 'Logoff', or chooses 'Exit',
> but also when they use the X button in the upper right corner, or
> whenever the program generates a run-time error and cannot continue.
> The latter example may not be possible, since the 'program cannot
> continue', but I'm looking for the best solution to call this
> function whenever my app exits, regardless of the method by which it
> exits.  Any help would be greatly appreciated.

Your 'logoff' and 'exit' options I assume are menus or command buttons...
the only code behind them should be 'Unload Me'.

In the Form_QueryUnload event add code if needed to verify that the app can
quit (including prompting the user if necessary).  Use 'Cancel=True' to
abort the unload.

In the Form_Unload event add code to close databases/files/etc, stop timers,
unload other forms and perform any other cleanup you need to do, including
calling the Logoff procedure.

The X on the form will trigger the Form_QueryUnload event and then the
Form_Unload event.  Using 'Unload Me' does the same thing (except the
UnloadMode parameter in Form_QueryUnload will be different).



Sun, 01 May 2005 07:56:59 GMT  
 Calling a Function on App Exit - No matter which method is used to exit
Hi,

Is this forms based?  If so, then the main form's Unload event subroutine is
fired before the app ends.

--
Richard Grier  (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 3rd
Edition ISBN 1-890422-27-4 (391 pages) published February 2002.



Sun, 01 May 2005 07:51:09 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Starting a program and then exit the calling app

2. Exit Sub from called Function

3. Recursive call and Exit Function

4. Exit Code from app run using ShellExecute

5. VB6 App exits without explanation when using DESKTOPTODEVICE

6. How do I code a menu Exit to exit

7. Exit For or Exit Do (with press one key)

8. Exit For or Exit Do

9. Can VB return exit code on program termination as exit(X) in C

10. Non-default methods of exiting formfields

11. Word exiting and sending back method ~ of object ~ failed

12. Unload (best method to exit a program)

 

 
Powered by phpBB® Forum Software