How detect when mouse moves out of a textbox ???

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a text box that must have a non-blank value before a button can be enabled

I'm using the 'on lostfocus' event but that does not trigger until I click someplace else
I want the button to enable immediately the mouse moves out of the textbox provided the contents are non blank

Is there any way
 
David said:
I have a text box that must have a non-blank value before a button
can be enabled.

I'm using the 'on lostfocus' event but that does not trigger until I
click someplace else.
I want the button to enable immediately the mouse moves out of the
textbox provided the contents are non blank.

Is there any way?

Theoretically, I guess, you could use the MouseMove event of the section
(Detail, Form Header, Form Footer) that contains the text box. But it
seems to me that it would make a lot more sense to use the AfterUpdate
event of the text box to determine whether the text box is now nonblank.
Of course, you'd have to have code in some preliminary event to
determine whether the control is initially blank and enable or disable
the button accordingly. That could be the form's Current event, or
maybe the control's Enter or GotFocus event.
 
Thanks for the reply. I have tried the 'lostfocus', 'exit' and 'after update' events and all require me to click someplace else to activate.
 
Not really. After you enter the value in the textbox, just press Tab or
Enter. Your AfterUpdate code will run, and if valid, the command button will
be made visible. Even if the button is next in the Tab order, the focus then
will move to the now visible button.

I concur with Dirk. I always use the AfterUpdate event for what you seek to
do.

--

Ken Snell
<MS ACCESS MVP>

hajksmnrtltabnwolkst said:
Thanks for the reply. I have tried the 'lostfocus', 'exit' and 'after
update' events and all require me to click someplace else to activate.
 
"hajksmnrtltabnwolkst" <[email protected]>
wrote in message
Thanks for the reply. I have tried the 'lostfocus', 'exit' and 'after
update' events and all require me to click someplace else to
activate.

But (a) what makes you think the user will use the mouse instead of the
keyboard to cause the focus to leave the control, and (b) what if the
user intends to use the mouse to do something on the menubar or toolbar,
or to work outside the application entirely?

I suppose you could use the Change event of the text box and test in
that event to see if the control's Text property has zero length. That
way you could enable or disable the button the instant the user begins
to change the text in the control.
 
An idea:

Put something around the textbox which triggers its own MouseMove o
MouseOver event (like a blank Image). When the mouse is over th
Textbox, have it set a flag. When the MouseOver event is triggered o
the Image, have it check if that flag is set; if so, then your use
just exited the textbox, if not, then they are probably just about t
enter the textbox
 
Back
Top