data input format

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.
 
G

Gary''s Student

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
 

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