Calculation in a form and storing results in a table

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Ok....Maybe I have been trying to figure this out to long and the answer is
right in front of me; but I just can get my form to the store the information
into the table.

My textbox called txtbxTotWt calculates the total weight of cable. I can get
the information to show on the form by using the following equation in the
control source
"=[wpf01]+[wpf02]+[wpf03]+[wpf04]+[wpf05]+[wpf06]+[wpf07]+[wpf08]+[wpf09]+[wpf10]+[wpf11]+[wpf12]+[wpf13]+[wpf14]+[wpf15]+[wpf16]+[wpf17]+[wpf18]+[wpf19]+[wpf20]+[wpf21]+[wpf22]+[wpf23]+[wpf24]".
Once calculated I want to store the information into a table called
"tblCTfill" and in the field called "TotWt".

I added the following into "After Update" Event

Private Sub txtbxTOTWT_AfterUpdate()
On Error Resume Next
TotWt = [txtbxTOTWT]
End Sub

Can any one help steer me in the right direction on what I maybe doing wrong?
 
Hi -

Here's one suggestion.

Put a command button on your form, and do the calculation in the
on-click event: [txtbxTotWt]=[wpf01] + [wpf01]+ ....

Set the control source of [txtbxTotWt] to "TotWt".

This assumes that the record source for the form is your table "tblCTFill".

HTH

John
 
I guess I can make the command button invisible and then just have the
results show in the txt box "Totwt"?
--
Heiko K Stugg


J. Goddard said:
Hi -

Here's one suggestion.

Put a command button on your form, and do the calculation in the
on-click event: [txtbxTotWt]=[wpf01] + [wpf01]+ ....

Set the control source of [txtbxTotWt] to "TotWt".

This assumes that the record source for the form is your table "tblCTFill".

HTH

John



Ok....Maybe I have been trying to figure this out to long and the answer is
right in front of me; but I just can get my form to the store the information
into the table.

My textbox called txtbxTotWt calculates the total weight of cable. I can get
the information to show on the form by using the following equation in the
control source
"=[wpf01]+[wpf02]+[wpf03]+[wpf04]+[wpf05]+[wpf06]+[wpf07]+[wpf08]+[wpf09]+[wpf10]+[wpf11]+[wpf12]+[wpf13]+[wpf14]+[wpf15]+[wpf16]+[wpf17]+[wpf18]+[wpf19]+[wpf20]+[wpf21]+[wpf22]+[wpf23]+[wpf24]".
Once calculated I want to store the information into a table called
"tblCTfill" and in the field called "TotWt".

I added the following into "After Update" Event

Private Sub txtbxTOTWT_AfterUpdate()
On Error Resume Next
TotWt = [txtbxTOTWT]
End Sub

Can any one help steer me in the right direction on what I maybe doing wrong?
 
No, it has to be visible in order for you to be able to click it, and
have the event code run.

You could also put that code in the after-update of some other required
field that you fill in after the separate weight boxes.

I suggest too that you 1) default all the weight boxes to 0, and 2) you
have a check somewhere that you have done the calculation before saving
the record.

John
 
No...That's not what I need....Let me explain a little further...maybe it
will clear it up.

There are 24 user selected combo box, where the user selects the item and
the weight is related to the that particluar item. The Total weight is a
summation of all the product weights. I want to show the user what the weight
is and then store it into the table. I do not want to have the user select a
calculation button.

BTW....Thanks for the help.
 
So, redo the calculation in code, or Requery the calculated Control, in the
AfterUpdate event of each of the user-selected items. If you choose to
leave it as a calculated Control, then you'll need to set the value of the
recalculated (requeried) Control into the bound Control whenever you do
that. But, if you are going to be calculating in VBA code, called from
those AfterUpdate events, you could just bind the Control for total weight.

But, 24 items of the same type, stored in a record, and displayed on a Form
raises the proverbial red flag about database design. There's some
probability that you should move that information to a related table, and
display it in a Form embedded in a Subform Control.

Larry Linson
Microsoft Access MVP
 
Back
Top