I have two codes for the same textbox. One which limits the user input to numbers only. (I'm not sure I need it with the other code). My problem is to wish to limit intake to numbers between 0000 and 9999. A four-digit number is required. My coding problem is with value <=0.1, if I change it to 0 or 1 the form accepts just a single digit. If I change it to 0000 or 0001 the code removes the leading 0's. I've tried formats and masks with no luck.
Any suggestions….
Any suggestions….
VBA Code:
Private Sub txtC_account_AfterUpdate()
If Not IsNumeric(Me.txtC_account.Value) Then
MsgBox "Please enter a 4-digit number from 0001 to 9999", vbCritical, "Account Number"
Cancel = True
ElseIf Me.txtC_account.Value <= 0.1 Or Me.txtC_account.Value > 10000 Then
MsgBox "Please enter a 4-digit number from 0001 to 9999", vbCritical, "Account Number"
Cancel = True
End If
If txtC_account.Value > 10000 And txtC_account.Value <= 0.1 Then
MsgBox "Account number not between 0001 and 9999", vbCritical, "Account Number"
End If
End Sub
Private Sub txtC_account_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If (KeyAscii >= 48 And KeyAscii <= 57) Then
KeyAscii = KeyAscii
Else
KeyAscii = 0
End If
End Sub