Re: formatting a calculated number field on a form

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




Myrna Larson wrote:
> 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
>
> >40
>
> 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.

The principles of tiered architecture tells us to use the data layer to
return raw values and use the front end to apply any formatting. Access
tends to blur the lines between these boundaries e.g. a .mdb file is
referred to as and 'Access database' even though it contains front end
elements such as reports and forms.

Worse, I see evidence of users embedding hard coded references to front
end elements in the database layer e.g. a Query object (a.k.a. a VIEW),
which is very much a data layer element, containing a form's control in
the SQL where clause. Using a tiered approach, entirely possible in
Access, would be to create a Parameter Query object (a.k.a. a
PROCEDURE, stored proc, etc) in the data layer with strongly typed
parameters (possibly supplying default values); the front end would
then invoke the Query/proc passing values as required.

Why is this tiered approach not favored in Access? I really have no
idea. I get the impression that most Access font end developers choose
to have forms with bound controls: always bound, always connected, the
data is immediately committed as soon as a control's value is changed,
etc. What criteria do they use to make this choice: default behavior,
less/no programming required, lack of/no specific training in computing
science, quick kludge due to time/cost constraints? Again, I have no
idea.

To answer your question less obliquely, if you can't/won't change to a
tiered approach, how about having the Query/VIEW return two columns:
one being the raw data which is kept hidden from the user but available
to the front end developer under the hood in the form, and one column
formatted for display purposes only.

.



Relevant Pages

  • Re: formatting a calculated number field on a form
    ... the user to set the filter criteria, but that I should develop my own form for ... >> I have created a query with a field that calculates ages as described ... >> are incorrectly included since the filter is comparing text rather than ... >The principles of tiered architecture tells us to use the data layer to ...
    (microsoft.public.access.forms)
  • Re: error: Cursor not returned from query
    ... Erland Sommarskog wrote: ... During my test I have created the following query. ... I would suspect that it's some data layer (such as ADO, ADO.NET, DAO, ... ADO.NET has ExecuteReader and ExecuteNonQuery methods on ...
    (comp.databases.ms-sqlserver)
  • Re: Help with Microsoft help on linking Access to Outlook
    ... Tools - references - tick Microsoft Outlook object library. ... in the criteria cell in the graphical query builder. ... the same filtered recordset every time. ... normal form to allow the normal filtering process and viewing of the ...
    (microsoft.public.access.formscoding)
  • Re: Help with Microsoft help on linking Access to Outlook
    ... in the criteria cell in the graphical query builder. ... use as the source in the routine. ... the same filtered recordset every time. ... normal form to allow the normal filtering process and viewing of the ...
    (microsoft.public.access.formscoding)
  • Re: Help with Microsoft help on linking Access to Outlook
    ... in the criteria cell in the graphical query builder. ... use as the source in the routine. ... the same filtered recordset every time. ... normal form to allow the normal filtering process and viewing of the ...
    (microsoft.public.access.formscoding)