B
BruceM
Myrna Larson said:I only used age at death as an example. I am also calculating other time
intervals, though not on the form. For example the interval between,
surgery
and heart attack, age 40 and heart attack, surgery and death, etc. I have
5
dates (birth, surgery, heart attack, last contact, death). I may want to
calculate the number of years between any two of those 5 dates.
Yes, sorry I was not more explicit about the purpose of the project, but
none
of these details have anything to do with my problem (formatting the
number)
or its solution, so I didn't provide them.
Sorry. I said the exact opposite of what I intended, which was that a
filter may well be your best choice. However, you would not need to write
multiple parameter queries. You could allow for any parameter to be blank.
You could search for all heart attack incidents in a date range, or all
incidents of any sort in a date range, or all heart attacks regardless of
date, or whatever you choose.
Why not? I may want to change the filter on-the-fly during an editing
session,
to double check certain items and in doing so, see ONLY the relevant
records,
for example see only those records that were updated in 2005 and have had
a
heart attack, or edited in 2005 and have had a stroke. I don't think
writing a
new parameter query for each possible scenario is worth the effort, as
each of
these filters would be used only once or twice at most.
In a way, I am calculating on the fly. The data form uses a query as its
data
source, and the 4 ages (surgery, heart attack, contact, and death) that
are
displayed on the form are automatically updated when the dates are
modified.
When I hear "field" I tend to think of a table field. Apparently you are
applying the format to a query field. My usual approach is to use forms to
view and change data, so I don't make much use of formatting in queries. I
got stuck on that point.
I don't need any help with calculating the age/time interval <g>. I've
been
programming in Basic since the 1970's, and problems relating to time
intervals, and calculations involving decimal years, happen to be one of
my
special interests.
I must admit that when I saw 'DateDiff("yyyy"' and the number 365.25 in
your
formula I dismissed it immediately. As I mentioned above, I am calculating
other intervals with this VBA procedure. Age at death was just one
example.
One might encounter an interval of only a few days when, say, a patient
has
surgery and suffers a heart attack 1 day later.
My first thought on reading the above, had I not followed the rest of this
thread, would have been that these are two separate incidents rather than
two fields in one record. Much of what I wrote earlier was centered on that
assumption, which I think is reasonable enough in the relational database
world.
Your solution began with the equivalent of this expression:
IIf(DateDiff("yyyy",[Date1],[Date2])=0
This will fail whenever the Date1 and Date2 are in the same calendar year:
the
expression will return 0. The biggest error would be the case of Date1 =
Jan 1
and Date2 = Dec 31. The correct result is 364/365 = 0.997, not 0.
Three decimal places offers a level of precision not possible with two
decimal places, of course. I suggested 365.25 only because with two decimal
places there is some imprecision anyhow. "yyyy" in the DateDiff expression
could have been "d".