tags:

views:

70

answers:

1

I like to run some code when a user closes my ms 2000 app. This is being bypassed by the user pressing alt F4 and not using the exit buttons provided, how do i disable this functionality? Alternatively, is there a way to catch this and run some code. Im trying to avoid using a hidden form by the way.

A: 

You should be able to use an autokeys macro.

http://msdn.microsoft.com/en-us/library/aa159349%28office.10%29.aspx

EDIT re Conmments

It may suit to create a hidden start-up form or to use your main menu to cancel the close event unless your button is pressed:

  1. Set the CloseButton propert of the form to No. You can alternately set the ControlBox property to No, which removes both the 'x' and the min max buttons.

  2. In the declaration's area of the form's VBA code, define the following variable:

    Public OK2Close As Boolean

  3. In the form's OnLoad event, place the following code:

    OK2Close = False

  4. On your form should be a button to close the form (or Quit the application if on the Main screen). In the OnClick event for this button, place:

    OK2Close = True DoCmd.Close '(or DoCmd.Quit for Main screen)

  5. In the form's Unload event, place:

    Cancel = Not OK2Close

From: http://tek-tips.com/faqs.cfm?fid=1870

Remou
in practice the autokeys function can't be used to capture ALT keystrokes, the article is wrong unfortunately according to http://www.experts-exchange.com/Microsoft/Development/MS_Access/Access_Coding-Macros/Q_22497478.html
g_g
using the Form_KeyDown(KeyCode As Integer, Shift As Integer) checking where Shift = 4 And KeyCode = vbKeyF4 in every form seems a possible route, but this is messy
g_g
I can't test this at the moment: http://support.microsoft.com/kb/245746 but it may be of interest.
Remou
I have added some comments.
Remou