a simple question on IIf function

jshooty

New member
Local time
Today, 01:20
Joined
Sep 15, 2007
Messages
8
I'm relatively new to access, and am trying to accomplish something that I think is relatively simple but, in my efforts, has lead to nothing but errors. What I am trying to do: I have a form in which I input dates for an event and a date of birth; from those two dates, I would like to generate an age of the person at the time the event occurred. I have written code using the date diff function that allowed for calculation of the age, displayed in years and months (i.e., I would be displayed as of today as being 43 years and 4 months old). That works well; however, I would like for a third box to display the age in days, but I want it to do the calculation only if the age is less than two months--otherwise, I would like for the box to read "Not calculated". I have tried IIf, and have tried Switch, and I'm sure if I ventured into macros (eek) I could do it there. But I am looking for something like an IIf function that would say (in layman's terms) if the age in years is 0 and the age in months is less than two, then the age in days is x. My current IIf statment reads:

IIf ([AgeYears)=0) & IIf ([AgeMonths]=0),=DateDiff("d",[DOB],[EventDate]), "Not calculated"))

I'm sure I am making a syntax error, since I'm kind of making this up as I go along--but if someone out there could correct it for me, I would be grateful.
 
figured out the age dilemma

I figured I wouldn't get many answers, since this has been posted many times in the past with various "solutions"--none of which in and of themselves seemed to suit my purposes. But between writing a little code of my own (a first) and cutting and pasting from various other posts, I have a form which calculates a person's age in years, months--and days, if they are under 2 months of age. If anyone stumbles across this post and is seeking to accomplish something similar, i'm sure my solution is considerably less graceful than it could be--but it seems to work. I'd be happy to share it if anyone needs it...
 
Pleased you got it sorted. The syntax is all over the place in your statement. You potentially also have an issue that your two alternative outputs are different datatypes. You can't combine text and dates in the same field.
 

Users who are viewing this thread

Back
Top Bottom