IIf statement and age

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

Guest

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
 
within your existing code,

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

Just change DateOfDeath to the field name in your table that carries this
data.
 
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
 
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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top