Inputbox to validate user date entry

I would like to take a user input (a date) via an OK / Cancel box... so I'm successfully using an input box.  

Now I would like to make sure the user input date is:
- Not later than todays date
- If the user presses "cancel" the input box will cancel
- If the user presses OK and it's not a valid date and later than today it will prompt for an entry again.

I'm using the following code but I can't get it to check dates correctly.  If I Dim sOutRxDate as a date... it helps but then I can't tell if the user pressed escape.

Any ideas?

Dim sOutRxDate As String

    Do Until IsDate(sOutRxDate) And sOutRxDate <= Now()
        sOutRxDate = InputBox("What date was the outside Rx was issued?" & vbCrLf & vbCrLf & vbCrLf, "Outside Rx")
        If StrPtr(sOutRxDate) = 0 Then Exit Sub 'User pressed cancel
    Loop

Open in new window


Thank you.
thandelAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

John TsioumprisSoftware & Systems EngineerCommented:
 Do
        sOutRxDate = InputBox("What date was the outside Rx was issued?" & vbCrLf & vbCrLf & vbCrLf, "Outside Rx")
        If StrPtr(sOutRxDate) = 0 Then Exit Sub 'User pressed cancel
     Loop Until IsDate(sOutRxDate) And Cdate(sOutRxDate) <= Now()

Open in new window

thandelAuthor Commented:
Oh me like!  The only issue is if the user presses OK without anything entered or the user enters text, I get a data type mismatch error.  Can this be resolved without an error message to the user?
irudykCommented:
Another alternative is the following:

Dim sOutRxDate As String

GetDate:
    sOutRxDate = InputBox("What date was the outside Rx was issued?" & vbCrLf & vbCrLf & vbCrLf, "Outside Rx")
    If StrPtr(sOutRxDate) = 0 Then Exit Sub 'User pressed cancel
    If Not IsDate(sOutRxDate) Then GoTo GetDate
    If CDate(sOutRxDate) > Now() Then GoTo GetDate

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.