Help with Text Boxes

  • Thread starter Thread starter Dana
  • Start date Start date
D

Dana

Tough to explain so here I go. I have 3 text boxes on the
form, Textbox1 textbox2 and textbox3. 1 and 2 have the
control source link to their appropriate cell in the main
table. Textbox1 is currency and textbox2 is a percentage
number. The problem is I use the control source textbox3
to build an expression to get the percentage of textbox1
using textbox2 digit and all comes up well on the form
perfectly, but textbox3's result on the form does not
load in the table??? I know its because the control
source for it is not linked to it??? How can I get it to
post in the table? Please help. Thanks to any or everyone
for taking the time to read this.
 
A textbox cannot have both an expression and a field name in the control
source. To save the value, you must have a textbox on the form that is bound
to the field and you must write the correct value into that textbox. You can
do this using VBA code in the form's BeforeUpdate event.

With this said, however, it's not often that a calculated value must be
saved into a table. So long as you have the other fields saved, you can
always recalculate the value from those fields; thus, saving the calculated
value is not an efficient use of database storage; and, if one of the values
from which the calculation is made should be changed, you must always be
sure to update the calculated value that you stored.
 
-----Original Message-----
Tough to explain so here I go. I have 3 text boxes on the
form, Textbox1 textbox2 and textbox3. 1 and 2 have the
control source link to their appropriate cell in the main
table. Textbox1 is currency and textbox2 is a percentage
number. The problem is I use the control source textbox3
to build an expression to get the percentage of textbox1
using textbox2 digit and all comes up well on the form
perfectly, but textbox3's result on the form does not
load in the table??? I know its because the control
source for it is not linked to it??? How can I get it to
post in the table? Please help. Thanks to any or everyone
for taking the time to read this.
.
Hi Dana,
what you want is to store the result of a calculation in a
table field (or cell in your description).

Applying Normalisation rules, it is generally considered
better design not to store calculated fields. Just store
the data fields. You then process calculations as you move
from record to record in forms or reports.

The main reason is to minimise the posibility for data
errors that may arise when data changes without forcing
recalculation. For example, when calculations are forced
in data entry form. But user maintains data directly in a
table. Thereby avoiding re-calculation of some fields.

As there are times when these rules can be broken - such
as achieving performance efficiency when you have either a
lot or complex calculations that slow down data analysis
or reports - here's how you can do this...

Have calculation in the query that is the record source
for the form - then same record source can be used for
reports so as to minimise possibility of different
calculations in every data user (form, report) - use
after_update() event of every data field control to put
calculated value into form field control.

For example, textbox3 has table field as controlsource

' common procedure to avoid duplication
' any changes to process handled in this procedure
private sub AssignToTextBox3()
textbox3=myQueryCalculatedField
end sub

' one of the data field controls....
private sub TextBox1_AfterUpdate()
' call common procedure
AssignToTextBox3
end sub

' one of the data field controls....
private sub TextBox2_AfterUpdate()
' call common procedure
AssignToTextBox3
end sub

Luck
Jonathan
 
Back
Top