How To Get An Event To Run When I Exit A TextBox
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
On Fri, 22 Oct 2004 13:07:50 -0400, "Tom Ogilvy"
wrote:
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
|