calling an _Exit event

S

SMS

Hi All...

The _Exit event for a textbox say, is called when leaving the textbox
(anything to cause a loss of focus, it seems).

I am used to being able to call events from code directly (ex: _change
events). This is proving harder for the _Exit event, as it requires a
special cancel argument. Using 0 or 1 or False or True does not work,
as it is not a normal boolean.

Could someone demonstrate for me how to call the _Exit event of a
textbox?

Thank you!

SMS
 
J

JLGWhiz

Don't know if this helps but this is from the VBA Help file:

The Enter and Exit events are similar to the GotFocus and LostFocus events
in Visual Basic. Unlike GotFocus and LostFocus, the Enter and Exit events
don't occur when a form receives or loses the focus.

For example, suppose you select the check box that initiates the Enter
event. If you then select another control in the same form, the Exit event
is initiated for the check box (because focus is moving to a different
object in the same form) and then the Enter event occurs for the second
control on the form.

Because the Enter event occurs before the focus moves to a particular
control, you can use an Enter event procedure to display instructions; for
example, you could use a macro or event procedure to display a small form or
message box identifying the type of data the control typically contains.

Note To prevent the control from losing focus, assign True to the Cancel
argument of the Exit event.
 
J

JLGWhiz

I re-read your post and I think this is what you are looking for:

If the TextBox is on a sheet and you call from within the sheet code module
or if it is on a UserForm and you call from the form code module:

Private Sub TextBox1_Exit()
'Code here
End Sub

Calling a Private Sub from outside its host (Sheet or UserForm) can be a
little tricky. For the UserForm, the form would have to be visible and
modeless. I have never tried to initiate an event code without actually
having the event occur and my dim wit cannot visualize how that would even
be necessary.
 
S

SMS

Hi,

thanks very much for trying...

actually, and I know it can make a difference, this is a control on a
userform.

I know how to write the _Exit event, what I need is a way to call the
event from code. It already triggers when the actual event
happens.... but I do like to be able to force the event.

Does that make sense?

SMS
 

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