Reputation: 159
Anybody knows how to check the input date format in the textbox in vba ?
I have this code but I'm uncertain of the output. The input format of the user should be in mm/dd/yyyy
. if not, then it will pop out a message saying: Use the mm/dd/yyy date format.
If Not Format(txtStartDate.Value, "mm/dd/yyyy") Then
MsgBox "Please use the mm/dd/yyyy date format."
txtStartDate.setFocus
Exit sub
End If
I'm just very unsure of what I'm into. thanks!
Upvotes: 1
Views: 2648
Reputation: 179
Dim regEx As New RegExp
regEx.Pattern = "^[0-9]{2}/[0-9]{2}/[0-9]{4}"
Dim inputstring As String
inputstring = "10/2/200"
If Not regEx.test(inputstring) Then
MsgBox "Please use the mm/dd/yyyy date format."
Exit Sub
End If
Upvotes: 3