Sum all fields in a tables column and put the sum result into a variable

wim1981

Registered User.
Local time
Today, 11:43
Joined
May 20, 2015
Messages
40
Hi everyone,

i would like to sum all the column fields in a tables column where an id is the same as the id in that table.
I know you can use the SUM function in the select statement of your query.

But how can i set this sum result into a variable, so i can use it for calculation further on in the program?

I work with Access 2010

Regards and thanks
Wim
 
In VBA declare a variable and assign it to the result - something like;

Code:
Dim MyResult as Long   
Dim iFilterID as Int       'Assuming it is a number

iFilterID = theIDvalue

MyResult = DSum("FieldToAddUp","TableWhereFieldIs","[IDField] = " & iFilterID)
 
In VBA declare a variable and assign it to the result - something like;

Code:
Dim MyResult as Long   
Dim iFilterID as Int       'Assuming it is a number

iFilterID = theIDvalue

MyResult = DSum("FieldToAddUp","TableWhereFieldIs","[IDField] = " & iFilterID)

Aha that's nice.
Didn't knew that you could set a sort of where clause into that code :D

I will try it out. Thanks
 
Hi Minty,

the Id parameter in my code is a String.

I have the following code:

Code:
uren_gevolgd_db = DSum("uren", "dbo_Lan_opleiding", "Id_landmeter =" ' & landmeterId & ' )

He gives all the time the error that landmeterId gives an error.

Wim
 
Hi Minty,

the Id parameter in my code is a String.

I have the following code:

Code:
uren_gevolgd_db = DSum("uren", "dbo_Lan_opleiding", "Id_landmeter =" ' & landmeterId & ' )
He gives all the time the error that landmeterId gives an error.

Wim

I've sorted it out! It was a matter of qoutes. So this Thread is Solved!
Thanks a lot Minty.:D

Regards
Wim
 

Users who are viewing this thread

Back
Top Bottom