Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

have a field on a form sum totals from text boxes? 1

Status
Not open for further replies.

pduncan

IS-IT--Management
Jun 20, 2003
203
US
I have 4 text boxes (txtA, txtB, ... all currency) that the user enters - I need to have a "total" (txtGrossTotal) that is the sum of the four. I would like to have the total value change as the values are entered. Then when the save button is pressed, write this value (txtGrossTotal) back to the table (tblListings.txtGrossTotal)

I tried using a "=sum([txtA]+[txtB]+[txtC]+[txtD])" for the txtGrossTotal and on the forms "on Dirty" a me.refresh - but that doesnt work.

Thanks,
PDUNCAN
Memphis, TN - USA
 
I forgot to say this:
the "sum" to txtGross total isnt working - I havent even addressed the writing of that value back to the table -

Thanks,
PDUNCAN
Memphis, TN - USA
 
I did something like this.
Make a field txtGrossTotal in the desired table.
Have it on the form. and in default value of the [txtGrossTotal] have this code.
=[txta]+[txtB]+[txtC]+[txtD]

Access form does save this value automaticly in the linked table when u save.




 
another thing to remmember.
[txta] [txtB] [txtC] [txtD] should be in the table to. If they are not the value in [txtGrossTotal] wont be right because it is linked with [txta] [txtB] [txtC] [txtD].
 
How are ya pduncan . . . . .

In the [purple]AfterUpdate Event[/purple] of the four textboxes, copy/paste the following:
Code:
[blue]Me.ReCalc[/blue]
This will take care of updating [purple]txtGrossTotal[/purple] on the fly.

As for [purple]txtGrossTotal[/purple], try this:
Code:
[blue]=sum(Nz([txtA])+Nz([txtB])+Nz([txtC])+Nz([txtD]))[/blue]

Calvin.gif
See Ya! . . . . . .
 
I tried this both ways that were suggested and the txtGrossTotal field still does not update (or save the value on closing)

Could there be a property set on this field that prevents it from being updated?

AceMan1: I assume I put the txtGrossTotal code in the default value property?

Thanks,
PDUNCAN
Memphis, TN - USA
 
pduncan . . . . .

Some things are not clear . . . so questions (please answer all):
[ol][li]Is this a single or continuous view form?[/li]
[li]Are the textboxes A,B,C,D [blue]bound to fields[/blue] in a table (thats is . . . are the [purple]ControlSources[/purple] of each a fieldname?[/li]
[li]Is it your intent to sum the columns of the textboxes or just add the values in the controls?[/li]
[li]Is [purple]txtGrossTotal[/purple] bound?[/li]
[li]What is the table name where your storing the data?[/li][/ol]
Note: calculations are rarely stored in a database, as they should always come out right (same data, same calculation, same answer). There are instances where this needs to be done (like holding previous balance in a banking statement), but even those are rare . . .

Calvin.gif
See Ya! . . . . . .
 
1. Yes - Single Form
2. Yes - each is bound to a field in tblListing (as is txtGrossTotal)
3. I want to add the (4) values that the user enters on the form. The total is displayed in txtGrossTotal.
4. Yes - it's bound to tblListing.GrossCost
5. tblListing


Thanks,
PDUNCAN
Memphis, TN - USA
 
In the AfterUpdate event procedure of each A,B,C,D textbox:
Me!txtGrossTotal = Nz(Me!txtA, 0) + Nz(Me!txtB, 0) + Nz(Me!txtC, 0) + Nz(Me!txtD, 0)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PHV,
that worked exactly as I needed. Thanks. I have been working on another project for the last week and just got a chance to get back to working on this. how about a star? I really appreciate the help from everyone.

Thanks,
PDUNCAN
Memphis, TN - USA
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top