A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Private Sub TextBox1_Change()
If Len(TextBox1) = 4 Then
'simulate hitting the [Enter] key
'by having it move to the next
'control in sequence on the form
'or you could move to another control
Me.TextBox2.SetFocus
'or move to button and click it!
CommandButton1.SetFocus
CommandButton1_Click
End If
End Sub
Private Sub CommandButton1_Click()
MsgBox "You entered 4 characters"
End Sub
The _Change() event fires each time you type into the text box, so once you've got the 4th character (in my example) in it, it goes off and does other stuff. You could validate the entry at this point also. Thing to remember here is you've kind of got to get that last character right! You can edit and backspace and such until you do get 4 characters (or other number you choose), but as soon as that last one goes in, then the code will take over.
BTW: Didn't have to move to the CommandButton before calling its _Click() event, but it was a way to get out of the TextBox1 control itself.