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!

add values together from different tables

Status
Not open for further replies.

gungfukid

Programmer
Apr 9, 2001
9
GB
I would like to add together integer values from a number of different tables and display the result in a text box. The problem that I am having is that I would like to add only the values that correspond to the selected record (selected with primary key) not the whole table. How do I write this in SQL?
Thanks!
 
You can use the DLookup function to go to foreign tables, find a value and extract it for use in your calculation. If you need to go to one table and get a couple different records summed and return the result you can use the DSum function. Both functions are used similarly and go something like this:

MyResult = DLookup("[MyFieldName]","MyTableName","[MyID]=[MyID]")

Now to add a couple different ones just string them together like so:

MyResult = (DLookup("[MyFieldName]","MyTableName","[MyID]=[MyID]")) + (DLookup("[MyFieldName]","MyOtherTableName","[MyID]=[MyID]"))

HTH Joe Miller
joe.miller@flotech.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top