Dsum - Pass a variable for the column?

I

idta

Can I pass a variable to dsum? I tried it and i got an error saying

"run-time error 2001 you cancelled the previous operation"

This was my example:

dim variable as string
variable = "1"
dsum("[variable]", "table1")

I get the error.

Any ideas?
 
I

idta

actually that doesn't work. it's giving me irrelevant sum.

When I say

dsum(1, "table1") for example, what result is dsum calculating?
 
T

Tom Wickerath

Idta,

Check out the following sample for the DLookup function on the MVPS site:

DLookup Usage Samples
http://www.mvps.org/access/general/gen0018.htm

Note that the same logic applies to other Domain Aggregate Functions,
including DSum. This form of your DSum statement should work just fine:

value = dsum("fieldname", "tablename")

However, it does not include any criteria so the sum will include all
records in the indicated field and table.


Tom

http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________

:

Figured it out, for future reference

value = dsum("[" & fieldname & "]", "tablename")
 
Top