Dates in VBA

S

Simon Guertin

Hi, I am trying to program with dates. I want to have a
function return a date or nothing if there is no date that
suits me. In vba it does not let me do this


dim mydate as date
....
....
if(not good) then
mydate = null
end if

the function is used in a query, should I use a string and
set it to null instead?
 
J

JohnR

Try:

dim mydate as date
.....
.....
if not IsDate(your date value) then
mydate = null
end if

From Access Help File:
IsDate Function

Returns a Boolean value indicating whether an expression
can be converted to a date.

Syntax

IsDate(expression)

The required expression argument is a Variant containing a
date expression or string expression recognizable as a
date or time.

Remarks

IsDate returns True if the expression is a date or is
recognizable as a valid date; otherwise, it returns False.
In Microsoft Windows, the range of valid dates is January
1, 100 A.D. through December 31, 9999 A.D.; the ranges
vary among operating systems.
 

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