kruk22
kruk22

Reputation: 159

Checking input date format

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

Answers (1)

King
King

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

Related Questions