Re: formatting a calculated number field on a form



I'll add my comments in-line below.

>I'm not sure how (or if) you got the Age function to work at all in Access,
>since as far as I know it is not an Access function.

A query in an MDB file CAN call a user-defined (i.e. VBA) function. I have
been doing that since I started this project, using Access 2000. I've now
upgraded to Access 2003.

How did I get it to work? The VBA code is in a module in the MDB file. The
function name is Age and it returns a double. I created the query in Design
View, using the grid. e.g. to calculate age at death, I use fields named DoB
and DoD. In the Field row of the query, I wrote AgeAtDeath:Age(DoB,DoD).

>calculating the number of days and dividing by 365.25.
>There may be some minor imprecision in some cases, but you can decide if
>that matters.

>AgeAtDeath:
>IIf(DateDiff("yyyy",[DoB],[DoD])=0,"",Format(DateDiff("d",[DoB],[DoD])/365.25,"Fixed"))
>Simplest way to sort and filter may be to add another field to the query:
>DateCriteria: DateDiff("yyyy",[DoB],[DoD])

I guess you haven't read any of my messages in the Excel forums in response to
formulas using 365.25 as the number of days in a year. Actually they may be
better described as "harangues" than "responses" <g>.

That formula is much more complicated than Age(Dob,Dod), I think you'll agree.
And for a patient who was born in, say, 1 Nov 2004, and died on 1 Feb 2005,
your first DateDiff will give a result of 0. I don't want 0, I want 0.25. And
there will be errors when the 2nd date is very close to the anniversary of the
birth date. The user will certainly "notice" if a patient was born on Jan 15,
1940, a heart attack occurred on Jan 15, 1989, and the age is shown as 48.99
or 49.01.

>Also, you can use Date()
>instead of [DoD] to calculate a living person's age.

No, I can't. I must use the date on which we last contacted the patient.
He/she could have died or had a heart attack, etc, since the last contact.

>Access serves a very different purpose than Excel. If you have multiple
>incidents for a single patient, is your approach to enter another complete
>record? If so, you are taking the long way around to avoid using the very
>aspect of Access that makes it a useful. The best way to do what you need
>is to have a Patients table with a record for each patient, and a related
>Incidents table to keep track of each individual incident. The only real
>way of entering multiple incidents for one patient in Excel is to enter the
>patient information over and over. In Access you enter the patient
>information once, and relate other information to that record.

I do understand the concept of a normalized data structure. I believe I have
it in my file. There is no repeated information from one record to the next.

I am only interested in the date and type of the FIRST incident. The patient
is removed from the study at that point. We are, however keeping track of the
count of heart attacks, I have a field for the date of the 1st event, what it
was (heart attack, stroke, etc), plus 4 numeric fields for the counts of the 4
kinds of problems we are tracking (heart attack, stroke, coronary artery and
carotid artery surgery).

I mentioned in an earlier post the problems with Excel that require me to use
Access.

>SQL is (among other things) the language behind a query.

Yes, I know that, and I have used it. When editing an SQL statement, I often
paste it into my editor program, where search and replace is available. In
another application, I use stock prices stored in an MDB file. I import those
into a spread*** using SQL queries that I contruct in the VBA code in the
spread***. So I am quite familiar with SQL, though I wouldn't say I'm an
expert.

>Parameter queries are the way Access provides for filtering data based on a
>particular field.

Is that what is happening "behind the scenes" when you use Filter-by-Form with
a Form? Or is the Filter property of the record set being changed?

>I suspect you are frustrated because an Access table resembles a
>spread***, but it is very different. Both have their uses, but they are
>not interchangeable.

No, that's not the issue. I understand the difference between a database and a
spread***, and when to use which.

My question pertained to problems with a FORM, not a data***, and that form
doesn't resemble a spread*** in any way. (I need a form for data entry: I
have too many fields to do it in data*** view, one of them is a memo field
of several hundred characters, including new lines, so editing them from
Data*** view is not really an option. In addition, I have lots of error
checking in my BeforeUpdate event procedure.)

>Your efforts seem to be centered on making an Access
>table behave like an Excel spread***.

Not at all! I just want control over the *display format* of a number that's
shown in a text box on a form. I've read messages here that say you can't
really apply formatting to a data*** view of a table or query -- that has to
be done in the form or report. And that's exactly what I have been trying to
accomplish: the format on the FORM.

I always want 2 decimal places, or when the result is 0, an "apparently" blank
cell. And I want to accomplish this WITHOUT changing the date type of the
underlying data from numeric to text or variant, so I can still filter on this
as a numeric field. And there IS a way to do all of that without an additional
field.

I guess you didn't see my last post, where I said I had solved the problem.
The answer is in the Format property for the field.

The problem I was having was that I entered this as the format:

0.00;;;

and Access changed that to a specification with only 1 section, i.e.

Fixed

My fundamental problem was not being able to find Help for "custom number
formats". Even though Help uses that term, the file is not indexed on it. You
have to search for help on "Format Property". The 2nd problem is that the
number format behaves a bit differently in Access than Excel, and without
Help, I didn't know that. The solution was to type the format string as

0.00; ; ; ;

Quite straightforward, once you know the "trick".

>It isn't going to happen, but maybe
>the folks in this group could help you get the most out of Access by making
>use of its capabilities.

I think I am getting what I need from Access now that this latest irritation
has been resolved.

Thanks anyway for your thoughts.
.


Loading