how to detect mouse click anywhere on a form

  • Thread starter Thread starter Mike Burnett
  • Start date Start date
M

Mike Burnett

I have a form with several text boxes named tb1, tb2, tb3, tb4, tb5,
etc. I would like to run VBA code whenever a mouse click occurs on
the form to determine if one of these text boxes has received the
focus. I know I can use Me.ActiveControl (or Screen.ActiveControl) to
get the name of the control with the focus. My question is: where do
I put the code to run every time a mouse click occurs on the form no
matter where the click is? I tried associating the code with a
Form_Click event, but that doesn't work.

Mike Burnett
(e-mail address removed)
 
Mike Burnett said:
I have a form with several text boxes named tb1, tb2, tb3, tb4, tb5,
etc. I would like to run VBA code whenever a mouse click occurs on
the form to determine if one of these text boxes has received the
focus. I know I can use Me.ActiveControl (or Screen.ActiveControl) to
get the name of the control with the focus. My question is: where do
I put the code to run every time a mouse click occurs on the form no
matter where the click is? I tried associating the code with a
Form_Click event, but that doesn't work.

You would have to call your code in the Click event of the form and in the
click event of every clickable object on the form. Wouldn't it be easier
to just use the GotFocus event of the controls you are worried about and
ignore other clicks?
 
Back
Top