Field Default values

  • Thread starter Thread starter Tony Williams
  • Start date Start date
T

Tony Williams

I have a table with a field name txtmonth and another field name
txtmonthlabel. I want the value of txtmonthlabel to always be
=Format([txtMonth],"mmmm yyyy") which is fine if I use that expression in a
text control on a form but the value isn't saved in the table. How can I use
that expression and get the value stored in the table ?
TIA
Tony Williams
 
I have a table with a field name txtmonth and another field name
txtmonthlabel. I want the value of txtmonthlabel to always be
=Format([txtMonth],"mmmm yyyy") which is fine if I use that expression in a
text control on a form but the value isn't saved in the table. How can I use
that expression and get the value stored in the table ?

Storing derived data such as this in your table accomplishes
three things: it wastes disk space; it wastes time (almost
any calculation will be MUCH faster than a disk fetch); and
most importantly, it risks data corruption. If one of the
underlying fields is subsequently edited, you will have data
in your table WHICH IS WRONG, and no automatic way to detect
that fact.

Just redo the calculation whenever you need it, either as a
calculated field in a Query or just as you're now doing it -
in the control source of a Form or a Report textbox.

If it's truly a *default* - that is a value which will usually be set
to an expression but which the user is allowed to override - you can
use VBA code on a Form to set it. Post back if that's your situation.

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps
 
Thanks John for those comments. It was more a case of was it possible to
save the value particularly as I was using it to link Child and Master forms
in a mainform tabbed subform.
Tony
John Vinson said:
I have a table with a field name txtmonth and another field name
txtmonthlabel. I want the value of txtmonthlabel to always be
=Format([txtMonth],"mmmm yyyy") which is fine if I use that expression in a
text control on a form but the value isn't saved in the table. How can I use
that expression and get the value stored in the table ?

Storing derived data such as this in your table accomplishes
three things: it wastes disk space; it wastes time (almost
any calculation will be MUCH faster than a disk fetch); and
most importantly, it risks data corruption. If one of the
underlying fields is subsequently edited, you will have data
in your table WHICH IS WRONG, and no automatic way to detect
that fact.

Just redo the calculation whenever you need it, either as a
calculated field in a Query or just as you're now doing it -
in the control source of a Form or a Report textbox.

If it's truly a *default* - that is a value which will usually be set
to an expression but which the user is allowed to override - you can
use VBA code on a Form to set it. Post back if that's your situation.

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps
 
Thanks John for those comments. It was more a case of was it possible to
save the value particularly as I was using it to link Child and Master forms
in a mainform tabbed subform.

You can link on a calculated field, or (more obscurely, but it *does*
work) by using the name of a textbox containing a calculated value as
the Master Link Field.

John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps
 

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