Avatar of thandel
thandel
 asked on

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.
Microsoft Access

Avatar of undefined
Last Comment
irudyk

8/22/2022 - Mon
John Tsioumpris

 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

thandel

ASKER
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?
ASKER CERTIFIED SOLUTION
irudyk

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Your help has saved me hundreds of hours of internet surfing.
fblack61