Date queston for Allen Browne

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello

I've been studying samples of code from your web site to improve my skill
level. In the fragment below, why do you declare varDOB as Variant, only to
later validate it as a Date in the If IsDate statement? Why not just declare
varDOB as Date? For that matter, why not declare Age as Integer instead of
Variant?


Function Age(varDOB As Variant) As Variant
......

If IsDate(varDOB) Then
dtDOB = varDOB
......

Thanks
 
Variant type can handle nulls as well as any other type of input.

If you were sure that the input would always be a date field, then there
would be no reason to use variant. However, in many cases (especially
with queries using the function) you may need to pass a null value into
the function and let the function detect whether or not you have passed
a null.

You could of course test the value before you passed it to the function

IIF(IsDate([SomeField]),MyFunction([SomeField]),Null)

Also, when returning a value if you want to send back a null in certain
cases, then you need to use variant as the return type.



'====================================================
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
'====================================================
 
Back
Top