dbTalk Databases Forums  

Invalid Use of Null

comp.databases.ms-access comp.databases.ms-access


Discuss Invalid Use of Null in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Coll
 
Posts: n/a

Default Invalid Use of Null - 12-20-2009 , 09:17 PM






I have the following code that is used to determine a person's age as
of the run date. I'm receiving an error message in my query related to
this function "Invalid use of null." I checked the values in the field
bdate, and they are all populated and are all less than (older) than
the current date. Can't seem to figure out what's causing the error.

Function yourAge(bdate) As Integer

Dim DateToday As Variant
DateToday = Date


If Month(DateToday) < Month(bdate) Or (Month(DateToday) = _
Month(bdate) And Day(DateToday) < Day(bdate)) Then
yourAge = Year(DateToday) - Year(bdate) - 1
Else
yourAge = Year(DateToday) - Year(bdate)
End If


End Function

Reply With Quote
  #2  
Old   
Allen Browne
 
Posts: n/a

Default Re: Invalid Use of Null - 12-21-2009 , 03:49 AM






Add a block around all your code (except the DIM statement):
If IsDate(bDate) Then

An example of how to write such a function:
http://allenbrowne.com/func-08.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.


"Coll" <col_mcmanus (AT) hotmail (DOT) com> wrote

Quote:
I have the following code that is used to determine a person's age as
of the run date. I'm receiving an error message in my query related to
this function "Invalid use of null." I checked the values in the field
bdate, and they are all populated and are all less than (older) than
the current date. Can't seem to figure out what's causing the error.

Function yourAge(bdate) As Integer

Dim DateToday As Variant
DateToday = Date


If Month(DateToday) < Month(bdate) Or (Month(DateToday) = _
Month(bdate) And Day(DateToday) < Day(bdate)) Then
yourAge = Year(DateToday) - Year(bdate) - 1
Else
yourAge = Year(DateToday) - Year(bdate)
End If


End Function

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.