validation rule, input mask?

A

alekm

Hi,
how can I make sure input in a text box would be like following:
xxxx/nn where xxxx is a number and its number of digits (one digit or more)
may vary and the nn is two digit string (number that may start with zero)
thanx
alek_mil
 
D

Douglas J. Steele

Private Sub MyTextBox_BeforeUpdate(Cancel As Integer)

Dim intLength As Integer

If IsNull(Me.MyTextBox) Then
Cancel = True
Else
intLength = Len(Me.MyTextBox)
If intLength < 4 Then
Cancel = True
Else
Cancel = (Mid$(Me.MyTextBox, intLength - 2, 1) <> "/") _
Or Not IsNumeric(right$(Me.MyTextBox, 2))
End If
End If

If Cancel = True Then
MsgBox "Input is invalid"
End If

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top