MS Access - GotFocus event

I’ve had great success posting here about solving problems in MS Access… so here comes another question…

Is it possible in Access to have the GotFocus event check to see if the focus was given from a mouse click or from being tabbed to.

I have a command button that on the GotFocus even asks if you want to proceed.
If you say yes, it runs the Click event.
I won’t go into why it does this, but there is a good reason…

However, I only want it to do this if the person tabbed to the button.
If the person clicked the button (or used the Alt-Hotkey) I do not want it to ask if you wish to proceed and I do NOT want it to call the Click event (otherwise the event runs twice, once from the call and once from the actual click).
The GotFocus event should do nothing and the Click event allowed to do its thing when the button is clicked.

I cannot find anything in the documentation about this… I have a feeling it’s not possible…

Any ideas?

Thanks…

I don’t think that the method that the control got the focus is passed to the OnGotFocus event … you may be able to do something using an OnKeyDown event on the previous control in the tab order. One way you could get the same effect would be to remove the button from the tab list and replace it with an invisible label field, and run the code from the OnGotFocus event for that field. Or, for virtually any application I can think of, just remove the button from the tab list and make the users click or use the hotkeys if they want to run the code. See my sig for a detailed explanation of this theory. :slight_smile:

Look at all your other events. The KeyPress event is called when you tab to a control, but the Click event is not called until you press Enter (or click it with the mouse). Forget about the GotFocus event and use these to decide which code to run.

How about using MouseDown instead of Click?

Sorry, but I have to ask: why the heck do you want to do this?

Thanks for the advice guys…

The reason I need to do this is because I have a bunch of tabs on a form.
Each of these tabs contains listboxes of data. They are quite lengthy and take a while to load so they don’t load right away… on the first try, it asks you if you want to “refresh” the list unless you click it, then it SHOULD go right away… that’s the theory…

Unfortunately, the KeyPress event didn’t do the trick… it doesn’t work before the gotfocus event…
I think the best bet is having a hidden text box (you can’t have a gotfocus event on a label)… but it’s not exactly high priority right now, so I’ll play with it later…

Thanks again…