IIf statement and age

P

Philip Wright

I'm wanting to calculate an age either by date of death or current date in a
query. How do I do this?

I currently have expressions to calculate current age, but if a patient is
deceased, I want it to display age at death instead of the current age.

Thanks.

Philip Wright
 
K

Klatuu

within your existing code,

IIf([DateOfDate] IS NULL, Date(), [DateOfDeath])

Just change DateOfDeath to the field name in your table that carries this
data.
 
D

Douglas J. Steele

I don't think you can use IS NULL in the IIf statement. Try:

IIf(IsNull([DateOfDate]), Date(), [DateOfDeath])

Of course, this is exactly what the Nz function is for:

Nz([DateOfDate], Date())

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Klatuu said:
within your existing code,

IIf([DateOfDate] IS NULL, Date(), [DateOfDeath])

Just change DateOfDeath to the field name in your table that carries this
data.

Philip Wright said:
I'm wanting to calculate an age either by date of death or current date
in a
query. How do I do this?

I currently have expressions to calculate current age, but if a patient
is
deceased, I want it to display age at death instead of the current age.

Thanks.

Philip Wright
 
K

Klatuu

In VBA you can't. In SQL you can.

Douglas J. Steele said:
I don't think you can use IS NULL in the IIf statement. Try:

IIf(IsNull([DateOfDate]), Date(), [DateOfDeath])

Of course, this is exactly what the Nz function is for:

Nz([DateOfDate], Date())

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Klatuu said:
within your existing code,

IIf([DateOfDate] IS NULL, Date(), [DateOfDeath])

Just change DateOfDeath to the field name in your table that carries this
data.

Philip Wright said:
I'm wanting to calculate an age either by date of death or current date
in a
query. How do I do this?

I currently have expressions to calculate current age, but if a patient
is
deceased, I want it to display age at death instead of the current age.

Thanks.

Philip Wright
 
P

Philip Wright

Thanks for the help. The Nz function worked as I wanted.

Douglas J. Steele said:
I don't think you can use IS NULL in the IIf statement. Try:

IIf(IsNull([DateOfDate]), Date(), [DateOfDeath])

Of course, this is exactly what the Nz function is for:

Nz([DateOfDate], Date())

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Klatuu said:
within your existing code,

IIf([DateOfDate] IS NULL, Date(), [DateOfDeath])

Just change DateOfDeath to the field name in your table that carries this
data.

Philip Wright said:
I'm wanting to calculate an age either by date of death or current date
in a
query. How do I do this?

I currently have expressions to calculate current age, but if a patient
is
deceased, I want it to display age at death instead of the current age.

Thanks.

Philip Wright
 
Top