Here's one way...
Object: TextBox
Name: txt_NewPassword
'/** Just in case they leave the text box without entering the right length
Private Sub txt_NewPassword_LostFocus()
'/** If nothing entered then don't worry about it
If (Len(txt_NewPassword.Text) = 0) Then
Exit Sub
End If
'/** Make sure it's the correct length
If (Len(txt_NewPassword.Text) <> 5) Then
MsgBox "Password must be 5 Digits.", , "Warning"
'/** Go to some other control
someothercontrol.setfocus
'/** Setfocus to the current TextBox
txt_NewPassword.SetFocus
End If
End Sub
'/** Make sure each entry is a digit
Private Sub txt_NewPassword_Change()
Dim aString As String
If (txt_NewPassword.Text = "") Then
Exit Sub
End If
aString = txt_NewPassword.Text
If (InStr("1234567890", Mid(aString, Len(aString), 1))) Then
If (Len(aString) > 5) Then
MsgBox "Max 5 Digits"
SendKeys "{BACKSPACE}"
End If
Else
MsgBox "Only Digits allowed."
SendKeys "{BACKSPACE}"
End If
End Sub
--------------------------------
Here would be the afterupdate method that you were thinking of
Private Sub txt_NewPassword_AfterUpdate()
-> check to see if it is the right length
-> if not then exit the sub
-> check to see if it is numeric
using isnumeric() function
the only problem is that a "." is considered a numeric value
-> so check if "." is in the text box
i.e. if (instr(password,".")) then
exit sub
end if
End Sub
Hope this helps
tc3of4
[This message has been edited by tc3of4 (edited 01-26-2001).]