How To Get An Event To Run When I Exit A TextBox

  • Thread starter Thread starter Minitman
  • Start date Start date
M

Minitman

Greetings,

I need to have a format command to wait until I have finished typing
in a TextBox and when I exit the TextBox for the format to run then.
I have checked the help files for what events are available and could
not find one that would work.

Any one have any suggestions?

TIA

-Minitman
 
If the textbox is in a userform, then use the Exit event.

In a worksheet, you would have to use one of the key events like KeyDown to
test for keys such as return or tab and perform you action then. Here is
some code Rob Bovey posted which is used to tab between textboxes on a
worksheet, but you can modify it to fit your needs. It too is looking for
the user to finish typing:

Private Sub TextBoxCurrent_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)
Dim bBackwards As Boolean
Select Case KeyCode
''' These are the only keys we care about.
Case vbKeyTab, vbKeyReturn, vbKeyDown, vbKeyUp
Application.ScreenUpdating = False
''' Determine if we need to move backwards.
bBackwards = CBool(Shift And 1) Or (KeyCode = vbKeyUp)
''' In Excel 97 we must select a cell
''' before activating another control.
If Application.Version < 9 Then Sheet1.Range("A1").Select
''' Activate the appropriate control based on key(s) pressed.
If bBackwards Then TextBoxPrevious.Activate Else _
TextBoxNext.Activate
Application.ScreenUpdating = True
End Select
End Sub
 
Try the event

Private Sub TBox_NAME_Exit(ByVal Cancel As MSForms.ReturnBoolean)

where TBox_NAME is the name of your text box
 
Hey Tom,

I appreciate this reply and all of the assistance you give so freely.

This solution is interesting but it goes a lot farther then I need.

Check out the other reply, it seems to be a bit more simplified.

-Minitman
 
If the textbox is in a userform, then use the Exit event.

Read my suggestion. The first suggestion I made was the exit event (which
only works for a userform). This is the same suggestion posted after me by
Mr. Datasort. without such qualification or explanation and which you found
so helpful. I then offered an alternative approach again, stating clearly
that this was if your textbox was not on a userform.
Check out the other reply, it seems to be a bit more simplified.
Kick me again <LOL>
 
Hey Tom.

I must apologize. I did not understand that "Exit" was the name of
the Exit event until I saw the code snippet. My only excuse is my
inexperience with VBA and writing code.

I did not mean to "Kick" you once or again.

Please accept my apology.

I find the knowledge and assistance you dispense so unselfishly to be
of great value. Please, don't let my ignorant babblings discourage
you in the pursuit of educating the unexperienced and uneducated
wannabe Excel programmers out here to comprehend the deepest mysteries
of Excel. <G>

-Minitman
 
I did say
Kick me again <LOL>

I guess I should have used "<g>" to be clearer - it was an attempt at grim
humor. No need to apologize. The original poster is always free to make
their own decisions. (and I am free to be Sardonic <g>)
 

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

Back
Top