M
Myrna Larson
My database consists of medical information and includes, specifically, the
age at which certain events may have occured. I have written VBA macro to
calculate the age.
For calculating, for example, the age at death, the arguments are the date of
birth (DoB) and the date of death (DoD). If a patient is alive, DoD is null,
and the VBA function returns a value of 0. If the patient has died, the age is
calculated in decimal years, rounded to 2 decimal places, e.g. something like
78.32.
I have created a query with a field that calculates ages as described above.
The expression used on the query for age at death is
AgeAtDeath: Age(DoB,DoD)
and it is formatted as Fixed.
The query is the data source for a form. I would like to achieve the following
appearance on the form:
1. For a live patient, I see 0.00. I want it to look blank.
2. For a dead patient that lived exactly 69 years, I see 69 rather than 69.00.
For a patient that lived 38.2 years, I see 38.2 rather than 38.20.
I can get around those 2 issues by changing the expression on the form to
something like
Iif(Age(DoB,DoD)=0,"",Format$(Age(DoB,DoD),"0.00"))
But now the field on the form contains text rather than a number, so there are
problems filtering correctly. If, for example, I want to see only patients who
died after age 40, I type in the Filter-by-form box
and Access changes that to
The consequence is that patients who died between the ages of 5.00 and 9.99
are incorrectly included since the filter is comparing text rather than
numbers.
Is there any way to achieve the desired format ('blank' or 2 decimal places)
while still having the field data treated as a number for the purpose of
filtering?
age at which certain events may have occured. I have written VBA macro to
calculate the age.
For calculating, for example, the age at death, the arguments are the date of
birth (DoB) and the date of death (DoD). If a patient is alive, DoD is null,
and the VBA function returns a value of 0. If the patient has died, the age is
calculated in decimal years, rounded to 2 decimal places, e.g. something like
78.32.
I have created a query with a field that calculates ages as described above.
The expression used on the query for age at death is
AgeAtDeath: Age(DoB,DoD)
and it is formatted as Fixed.
The query is the data source for a form. I would like to achieve the following
appearance on the form:
1. For a live patient, I see 0.00. I want it to look blank.
2. For a dead patient that lived exactly 69 years, I see 69 rather than 69.00.
For a patient that lived 38.2 years, I see 38.2 rather than 38.20.
I can get around those 2 issues by changing the expression on the form to
something like
Iif(Age(DoB,DoD)=0,"",Format$(Age(DoB,DoD),"0.00"))
But now the field on the form contains text rather than a number, so there are
problems filtering correctly. If, for example, I want to see only patients who
died after age 40, I type in the Filter-by-form box
and Access changes that to
"40"
The consequence is that patients who died between the ages of 5.00 and 9.99
are incorrectly included since the filter is comparing text rather than
numbers.
Is there any way to achieve the desired format ('blank' or 2 decimal places)
while still having the field data treated as a number for the purpose of
filtering?