Results 1 to 8 of 8
  1. #1
    jrickels is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2009
    Posts
    5

    Adding Totals to a query using queryDef

    In Access 2007 we are able to add totals to the bottom of queries, I was wondering if it is possible to add totals to a query in vba using a queryDef?

  2. #2
    llkhoutx is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Jan 2010
    Location
    Houston, Texas USA
    Posts
    373
    Sure, just use a group query on your query, but only on field to be summed.

  3. #3
    jrickels is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2009
    Posts
    5
    Maybe you are misunderstaning my problem (or I could be misunderstanding your solution) . Here's the whole situation, keep in mind I know there are other ways around this and in the future I plan on changing the setup of it, but until then I was hoping for an easy solution to get me by.

    I have a query that I create using a query def in vba code (because I change the source of the query several times). After I create the query, I can go in and manually add the totals by clicking the Totals button on the Home Ribbon and defining that I want a sum in each of the numeric columns. When I look at the SQL of this query after making this change it did not change from the original version set up using the query def. There for I decided it was a property of the query, so I was wondering if there was a way to change/add that property to a query using vba code?

  4. #4
    llkhoutx is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Jan 2010
    Location
    Houston, Texas USA
    Posts
    373
    You don't say that you save the query after you've summed appropriate columns.

    You can programmatically determine which columns are numeric and then programmatically build a SQL string which sums those columns.

  5. #5
    c_smithwick is offline Underpaid Programmer
    Windows 7 Access 2003
    Join Date
    Jan 2010
    Location
    Lakeside, CA
    Posts
    49
    For example:

    Code:
    SELECT Sum(tblTest.Field1) AS SumOfField1, Avg(tblTest.Field2) AS AvgOfField2, Count(tblTest.Field3) AS CountOfField3 FROM tblTest

  6. #6
    jrickels is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2009
    Posts
    5
    yes, I save the query after I've summed up the columns

    I need all of the detail and the totals in one query. I know how to get the total of each of the columns, but that is not what I'm looking for. I am wondering if anyone knows how to change/update the property of 'Totals' on a query if it is possible

  7. #7
    c_smithwick is offline Underpaid Programmer
    Windows 7 Access 2003
    Join Date
    Jan 2010
    Location
    Lakeside, CA
    Posts
    49
    Code:
    SELECT TblData.[Field1], TblData.[Field2], TblData.[Field3]  FROM TblData
    UNION SELECT Sum(TblData.[Field1]) AS [Field1], Sum(TblData.[Field2]) AS [Field2], Sum(TblData.[Field3]) AS [Field3] FROM TblData;
    Last row of the query result will be the totals. All fields must be named the same as the select query for it to work however

  8. #8
    jrickels is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2009
    Posts
    5
    That's creative, thank you. I will probably end up using that.

    I'm taking the lack of response as no one knows how to add the 'Totals' property to a query,if it is possible.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Query - using Max Totals with Criteria
    By mslieder in forum Access
    Replies: 1
    Last Post: 06-19-2013, 06:02 AM
  2. Totals in a query-based report
    By babylikesburgh in forum Reports
    Replies: 4
    Last Post: 02-24-2010, 03:08 PM
  3. Replies: 7
    Last Post: 12-07-2009, 07:27 AM
  4. Replies: 1
    Last Post: 03-15-2007, 03:38 PM
  5. query - totals
    By mslieder in forum Access
    Replies: 0
    Last Post: 02-22-2006, 06:11 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums