how to detect mouse click anywhere on a form

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)
 
R

Rick Brandt

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top