Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text Box Limit 1

Status
Not open for further replies.

dbero

Technical User
Mar 31, 2005
109
US
I would like to limit the text typed into a text box to 5 alpha numeric characters. if length is <>5, a message box appears and focus is set back to that text box. However, focus does not go back to the field, it goes to the next tab index even though I code it to. Any suggestions?
thanks

I put in the following code on Lost focus;
AgtNum = TxtAgntNum.Value
Length = Len(AgtNum)
If Length <> 5 Then
Response = MsgBox("Incorrect Agent Number. Must be 5 digits", vbOKOnly)
Forms![Agent Address Change]!TxtAgntNum.SetFocus
Exit Sub
End If
 
Put it in the Before Update event and add the line

Cancel = True

to the conditional statement that fires if Len <>5.

That will keep the focus on that textbox until the condition is met.


Paul
 
How about using the Before Update event and Cancel?
 
wow, great minds think a like....and the two of you do too!

[rofl]

Les
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top