For a bound control or an unbound control set MaxChars to the number of characters you want to allow. The example is set for 10.
Code:
Private Sub YourTextBox_Change()
Dim MaxChars As Integer
MaxChars = 10
If Len(Me.YourTextBox.Text) = MaxChars Then
NextTextBox.SetFocus
End If
End Sub
For bound controls only you can let Access set the MaxChars according to the Field Size as defined in the table:
Code:
Private Sub YourTextBox_Change()
Dim MaxChars As Integer
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Set db = CurrentDb
Set tdf = db.TableDefs("YourTableName")
Set fld = tdf.Fields("YourTextBox")
MaxChars = fld.Size
If Len(Me.YourTextBox.Text) = MaxChars Then
NextTextBox.SetFocus
End If
End Sub
For the second code to work, you must have a reference set for DAO.
Very Nice That worked for my text box containing text characters. How would I get this to work for 1) A text box containing an input masked 9 digit zip code, 2) A text box containing an input masked 10 digit phone number and 3) A text box containing an input masked 7 character medium-date date? And all are bound.
Input Masks as a whole are evil, but they do make this task a snap! In Design View, with the textbox selected, goto Properties - Other and change the AutoTab property to Yes.
When the appropriate characters have been entered Access will move to the next control as set forth in the Tab Order.
OMG, Thank you Missinling. Although I have more knowledge than the average db user, I find that the lack of forming training in this area causes me to miss the most obvious details. Sorry for bothering u with something I should have already known. And thank you again.