A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

#error in calculate age



 
 
Thread Tools Display Modes
  #1  
Old July 26th, 2008, 11:58 PM posted to microsoft.public.access.gettingstarted
Song[_2_]
external usenet poster
 
Posts: 13
Default #error in calculate age

I have a field [DOB] for date of birth. Some records are blank in this
field. If non-blank, I want to calculate age, otherwise, blank as follows:

=IIf(IsNull([DOB]),"",DateDiff("yyyy",[DOB],Now())+Int(Format(Now(),"mmdd")Format([DOB],"mmdd"))
& " Yrs")

Record with DOB field is calculated correct age. DOB blank still gives me
#Error. Which part did I do wrong? Thanks.

  #2  
Old July 27th, 2008, 02:51 AM posted to microsoft.public.access.gettingstarted
John W. Vinson/MVP
external usenet poster
 
Posts: 325
Default #error in calculate age

On Sat, 26 Jul 2008 15:58:58 -0700, "Song" wrote:

Record with DOB field is calculated correct age. DOB blank still gives me
#Error. Which part did I do wrong? Thanks.


Access may be upset about mixing datatypes. The DateDiff function
returns an Integer, the literal "" returns a Text type. Try

=IIf(IsNull([DOB]),Null,DateDiff("yyyy",[DOB],Now())+Int(Format(Now(),"mmdd")Format([DOB],"mmdd"))

--

John W. Vinson/MVP
  #3  
Old July 27th, 2008, 04:01 PM posted to microsoft.public.access.gettingstarted
Song[_2_]
external usenet poster
 
Posts: 13
Default #error in calculate age

I tried your method. Blank DOB still produce #error. Non-blank DOB
calculated correctly.

"John W. Vinson/MVP" wrote in message
...
On Sat, 26 Jul 2008 15:58:58 -0700, "Song" wrote:

Record with DOB field is calculated correct age. DOB blank still gives me
#Error. Which part did I do wrong? Thanks.


Access may be upset about mixing datatypes. The DateDiff function
returns an Integer, the literal "" returns a Text type. Try

=IIf(IsNull([DOB]),Null,DateDiff("yyyy",[DOB],Now())+Int(Format(Now(),"mmdd")Format([DOB],"mmdd"))

--

John W. Vinson/MVP


  #4  
Old July 27th, 2008, 06:55 PM posted to microsoft.public.access.gettingstarted
John Spencer
external usenet poster
 
Posts: 2,364
Default #error in calculate age

It is possible that your field is not a DateTime field, but is a text
field that stores a string that looks like a date. In that case, you
may need to test for a zero-length string or a null or just test to see
if Access can treat whatever is in the field as a date using the IsDate
function.

IIF(IsDate([Dob]),DateDiff("yyyy",[DOB],Now())+Int(Format(Now(),"mmdd")Format([DOB],"mmdd")),Null)

'================================================= ===
John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
'================================================= ===


Song wrote:
I tried your method. Blank DOB still produce #error. Non-blank DOB
calculated correctly.

"John W. Vinson/MVP" wrote in message
...
On Sat, 26 Jul 2008 15:58:58 -0700, "Song" wrote:

Record with DOB field is calculated correct age. DOB blank still
gives me
#Error. Which part did I do wrong? Thanks.


Access may be upset about mixing datatypes. The DateDiff function
returns an Integer, the literal "" returns a Text type. Try

=IIf(IsNull([DOB]),Null,DateDiff("yyyy",[DOB],Now())+Int(Format(Now(),"mmdd")Format([DOB],"mmdd"))


--

John W. Vinson/MVP


  #5  
Old July 27th, 2008, 08:45 PM posted to microsoft.public.access.gettingstarted
Song[_3_]
external usenet poster
 
Posts: 17
Default #error in calculate age

That's it! My DOB IS text field. Use your code and it works perfect. Thanks.

"John Spencer" wrote in message
...
It is possible that your field is not a DateTime field, but is a text
field that stores a string that looks like a date. In that case, you may
need to test for a zero-length string or a null or just test to see if
Access can treat whatever is in the field as a date using the IsDate
function.

IIF(IsDate([Dob]),DateDiff("yyyy",[DOB],Now())+Int(Format(Now(),"mmdd")Format([DOB],"mmdd")),Null)

'================================================= ===
John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
'================================================= ===


Song wrote:
I tried your method. Blank DOB still produce #error. Non-blank DOB
calculated correctly.

"John W. Vinson/MVP" wrote in message
...
On Sat, 26 Jul 2008 15:58:58 -0700, "Song" wrote:

Record with DOB field is calculated correct age. DOB blank still gives
me
#Error. Which part did I do wrong? Thanks.

Access may be upset about mixing datatypes. The DateDiff function
returns an Integer, the literal "" returns a Text type. Try

=IIf(IsNull([DOB]),Null,DateDiff("yyyy",[DOB],Now())+Int(Format(Now(),"mmdd")Format([DOB],"mmdd"))

--

John W. Vinson/MVP



 




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 Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 01:21 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.