data input format

  • Thread starter Thread starter Roy Gudgeon
  • Start date Start date
R

Roy Gudgeon

Hi

I have a user entry form and need to ensure the correct data format is used
when entering. At the moment it is a text box on a VBA data entry form, I
want to code the text box to only accept dd/mm/yy format.
 
If you get the dat as a string, then you can perform very specific tests on
parts of that string. For example:

Sub StrictFormat()
Dim s As String, i As Integer
s = Application.InputBox(prompt:="Date?", Type:=2)

If Len(s) <> 8 Then
MsgBox "Bad Format"
Exit Sub
End If

ary = Split(s, "/")

If UBound(ary) <> 2 Then
MsgBox "Bad Format"
Exit Sub
End If

i = ary(0)
If i > 31 Then
MsgBox "Bad Format"
Exit Sub
End If

i = ary(1)
If i > 12 Then
MsgBox "Bad Format"
Exit Sub
End If

End Sub
 
Back
Top