Change Event — Event Procedures Example
The following example counts the number of characters entered in a text box. If more than three characters are entered, a message is displayed and the count is reset to 0.
To try the example, add the following event procedure to a form named Orders that contains a text box named ShipRegion.
Private Sub ShipRegion_Change()
' Declare variable as static to preserve value between calls.
Static intLetter As Integer
' Check to see how many letters have been entered.
' If more than three, reset value of text box.
If intLetter < 3 Then
intLetter = intLetter + 1
Else
MsgBox "Only three characters are allowed."
intLetter = 0
Forms!Orders!ShipRegion.Undo
End If
End Sub