Dsum - Pass a variable for the column?

  • Thread starter Thread starter idta
  • Start date Start date
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?
 
actually that doesn't work. it's giving me irrelevant sum.

When I say

dsum(1, "table1") for example, what result is dsum calculating?
 
Figured it out, for future reference

value = dsum("[" & fieldname & "]", "tablename")
 
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")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

DSum Problem 4
dsum - 1
Dsum Issues 0
dsum 9
DSum Problem 2
DSUM with variables 1
Access DSum Calculations adding a third optional criteria? 2
DSum Countrol Source Help 5

Back
Top