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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

adding a total

Status
Not open for further replies.

lancemeroniuk

Technical User
Nov 1, 2001
22
CA
Hi all.. just setting up my dbase for a trucking company

question.. on my form I have a total box... In my quirre I can get the figures to add together.. now I need to show this total in the form.

Any suggestions yould be helpful..
Thanks


 
You can use the Dsum Function. I am not sure how you are doing what so I will give you an example.

In the OnCurrent() Event in the forms properties you would create an event procedureand in that event procedure is where you would use the Dsum() Function:

DSum("[Field To Sum]", "Table Field Is In")

you can also have a criteria in the DSum() Function. Say for example you just wanted to do total only one employee you could use that Employee's ID as the criteria to sum just employee's total.

DSum("[Field To Sum]", "Table Field Is In", "EmployeeID")

if you need any more help let me know.
email toeshot@hotmail.com

HTH

 
Mistake on my last post, the DSum with criteria should look like this
DSum("[Field To Sum]", "Table Field Is In", "EmployeeID = 11223345")

 
How do you have your form set up? I'm assuming the whole form is not based on the querry. One way to do it is with VBA using DLookup.

For example, say I have a table named tbl1 with a column of numeric values named myVals and a primary key named myIndex. I could assign it to a textbox named txtTotal with the following:

Code:
txtTotal = DLookup("myVals","tbl1","myIndex = 1")

To get the total number of records, use the count() method with no arguments.

Code:
txtTotal = DLookup("count(myVals)","tbl1")

To get the sum, use the sum method.

Code:
txtTotal = DLookup("sum(myVals)","tbl1")

etc..

If you already have a saved query.. you can reference it the same way.. just use the format:

Code:
DLookup("columnName","QueryName","arguments" (optional)

There are a few other ways to do this.. depending on you situation.. this may or may not work. If it doesn't, give me a little more info about your form and I'll see what I can do. -Dustin
Rom 8:28
 
THANKS ALL... Here is what I hav set up. on my form I have a box for

shipping cost... $...
fuel surcharge... $...
other costs... $...
total... this is the total of all the above..

I would like the "total" to show in the form, so that we do not have to manually add these.

Next question: when entering information into my form.. can I have the form autofill the criteria. Such as a reptive address or customer name??

Thanks for the help...
lance
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top