Query with Totals via VBA

cstimart

Well-known Member
Joined
Feb 25, 2010
Messages
1,180
I have an Access 2007 database. The user selects the Year/Quarter combination and pushed a button to display the resulting query, which the code creates as a temporary query.

Is it possible to have that query display totals at the bottom, and for specific columns....or do I need to create a permanent query with the totals and then change the SQL before opening when the button is selected?
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
display totals at the bottom You cannot do this with a query but you can with a report. You can create a Totals query, but the values returned in their respective fields will be at the top only of one row of data, or on every row in their field, depending on how other fields are grouped. By values I mean the results of the calculations being performed.

or do I need to create a permanent query with the totals and then change the SQL before opening when the button is selected?
I don't understand the question or how it relates to having totals at the bottom.
 
Upvote 0
or do I need to create a permanent query with the totals and then change the SQL before opening when the button is selected?
I don't understand the question or how it relates to having totals at the bottom.

My query is a list of records, which when you view the datasheet, you can use the Sigma in the Home ribbon to add a Totals row at the bottom...which you can then select certain columns to calculate a Sum, Average, Count, etc...

What I ended up doing was creating a permanent query which had the columns selected to calculate the Sum....then when the button is pushed with different Year/Quarter combination selected, then I revise the existing query using..

Code:
CurrentDb.QueryDefs("ByQuarter").SQL = "SELECT ...."

Problem solved.
 
Upvote 0
Good that you got it solved, but I'm beginning to think you are referring to the datasheet view of a form. I didn't see anywhere in your original post that you were opening a form - I thought you were referring to the datasheet view of a query. display the resulting query
 
Upvote 0
Nope...it's a query....just a basic query (for example) that would gather a list of all the records from tblText that the Job Date was in 2015 Q1....then when viewing that datasheet, totaling the sum of the hours and sum of the widgets created, etc...
 
Upvote 0
Then you gotta tell me - how do you get the totals at the bottom of this query in datasheet view?
And what version you're using.
 
Upvote 0
Access 2007 - create a basic query, goto the Datasheet View and utilize the Sigma on the home ribbon to include a Totals row....then each column should have a drop down list to select Sum, Average, Count, etc...
 
Upvote 0
I see what you mean. Feel like a moron now - been using Access since version 2.0 and never knew this.
 
Upvote 0

Forum statistics

Threads
1,221,844
Messages
6,162,346
Members
451,760
Latest member
samue Thon Ajaladin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top