Date Range Validation Rule

S

SillyRabbit

Hi,
Looking for the cleanest (read less code) to validate a
date range input value. Example: DateofService label for
two input boxes - From 3/1/04 thru 2/1/04 - How do I
prevent this from occuring? Obviously we can't go back in
time (at least not yet!). And display a simple error msg
box. Also, to prevent a date range in the future ( 3/1/05 -
3/5/05). This app is primarliy used for patients visiting
a doctor's office (not making an appointment BUT the dates
they stayed in the clinic).
 
J

John Spencer (MVP)

Assuming that you are storing the results of the input boxes into two variables
- dteOne and dteTwo

If IsDate(dteOne) = False or IsDate(dteTwo) = false then
MsgBox ...
ElseIf dteOne > dtetwo
MsgBox ...
ElseIf dteOne > Date() or dteTwo > Date() then
msgBox
Else
'Execute your code


End if
 
D

Dirk Goldgar

John Spencer (MVP) said:
Assuming that you are storing the results of the input boxes into two
variables - dteOne and dteTwo

If IsDate(dteOne) = False or IsDate(dteTwo) = false then
MsgBox ...
ElseIf dteOne > dtetwo
MsgBox ...
ElseIf dteOne > Date() or dteTwo > Date() then
msgBox
Else
'Execute your code


End if

Isn't that redundant, John? If we've already established, with
ElseIf dteOne > dtetwo
MsgBox ...

that dteOne is less than or equal to dteTwo, then the next test need
only be

ElseIf dteTwo > Date() Then
MsgBox ...

No?
 
J

John Spencer (MVP)

Yes, you are probably correct.

I just sometimes repeat tests for human readability. It may take the computer a
bit longer, but it is easier for me to read and easier for me to be sure that
I've tested everything I need to test.
 

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