Date Range Validation Rule

  • Thread starter Thread starter SillyRabbit
  • Start date Start date
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).
 
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
 
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?
 
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.
 
Back
Top