how to check if date is correct?

  • Thread starter Thread starter troubleD
  • Start date Start date
T

troubleD

I would like to ask how to tell in making a query to check if the date
selected is valid or not:

if isdate(dateBought)=true then 1 else 2


thank you
 
I would like to ask how to tell in making a query to check if the date
selected is valid or not:

if isdate(dateBought)=true then 1 else 2


thank you

What's the context? You certainly cannot use the VBA language if... then...
else construct in a Query, but you can use the builtin IIF function:

IIF(IsDate([DateBought]), <value if yes>, <value if no>)

to return a value. You cannot affect the flow of control, though, because
queries are not procedural and do not have a flow of control!
 
The question seems non-sensical.

For a field named dateBought in a query, if the datatype of the field in the
underlying table is set to DateTime, that will prevent any data other than a
valid date being entered into that field. If you have a field that you want
to enter dates into, then you should set its datatype to DateTime; you
should NOT, for example, set it to Text.

Or do you mean something else by "valid"?

Or are you using "query" in a non-Access sense? Your psuedo-expression
seems more like VBA code than a calculated field in a query.

Please explain more clearly exactly what you are trying to do.

Rob
 
How do you decided whether a date is valid?

Is it previous to a certain date, later than or between two dates?
 
thank you so much! this means a lot to me! thank you! :D

John W. Vinson said:
I would like to ask how to tell in making a query to check if the date
selected is valid or not:

if isdate(dateBought)=true then 1 else 2


thank you

What's the context? You certainly cannot use the VBA language if... then...
else construct in a Query, but you can use the builtin IIF function:

IIF(IsDate([DateBought]), <value if yes>, <value if no>)

to return a value. You cannot affect the flow of control, though, because
queries are not procedural and do not have a flow of control!
 
unfortunately the datatype was set to 'text' so i want to tell via sql
statement if the date was valid or not.

thank you
 
Back
Top