Code For Date Accepts Text

G

Guest

Can someone tell me what is wrong here? Am asking the user to input a date
in the mm/dd/yy format. It works ok except that it accepts any text string
that is entered (it rejects something like January 3, 2006 though).
Obviously, I do not want it to accept text, and cannot figure out how to fix
this. Any help would be appreciated....am sure it is something simple.

Sub SWStartDate()
Dim UserEntry As String
Dim Msg As String
Msg = "Enter the contract start date, in mm/dd/yy format; then click on 'OK'."
Do
UserEntry = InputBox(Msg)
If UserEntry = "" Then
MsgBox ("You must enter a response; please try again.")
End If
If UserEntry <> "" Then
If UserEntry = Format(UserEntry, "mm/dd/yy") Then
Exit Do
End If
If UserEntry <> Format(UserEntry, "mm/dd/yy") Then
Msg = "Invalid entry; please enter a date in the mm/dd/yy
format."
End If
End If
Msg = "Invalid entry; please enter a date in the mm/dd/yy format."
Loop
Worksheets("Software Inventory").Range("C5").Value = UserEntry
End Sub
 
R

Ron de Bruin

Hi Paige

Use the VBA IsDate function to test if Msg is a date
See VBA help for IsDate
 

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