Reputation: 373
I am learning Access and VBA. I'm using Access 2007.
I'd like to create something in VBA that runs a query and then returns a value in a message box, that value being the Total Sum of one of the columns.
The column that is summed is called Documents. The Query lists all the groups of documents still active, but what's most important is the sum. I want to create VBA for a button on the main form that runs each different query and then tells me the sum it gets when it runs each one.
How do I do this? I don't know how to use the number that Access calculates as the sum total as an object in VBA.
Upvotes: 2
Views: 3996
Reputation: 2244
Aggregating or summarizing data from a query or table in VBA often makes use of the domain aggregate functions: DSum (as here), DLookup, DCount, and so forth.
MsgBox "Total documents: " & DSum("Documents", "[Query Name Here]", "[Criteria] = ""Optional""")
Upvotes: 1