Results 1 to 5 of 5
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919

    Using SUM function in a UNION query

    I need to bind the Control Source of a text box on the SUM of [Amount] based on the query below. What do I add to the SQL shown below such that I can use the query name as the Control Source of a text box.



    Code:
    SELECT ALL 
    [DonRegFam].[FundID],[Funds].[FundTitle],[Funds].[AccountNo],[Funds].[Source],[DOE],[Amount],[Type]
    FROM [DonRegFam] INNER JOIN
    [Funds] ON [DonRegFam].[FundID] = [Funds].[FundID]
    Where DOE = DOEparms() AND Type = 3
    
    UNION ALL SELECT
    [DonRegInd].[FundID],[Funds].[FundTitle],[Funds].[AccountNo],[Funds].[Source],[DOE],[Amount],[Type]
    FROM [DonRegInd] INNER JOIN
    [Funds] ON [DonRegInd].[FundID] = [Funds].[FundID]
    Where DOE = DOEparms() AND Type = 3
    
    UNION ALL SELECT
    [DonUnReg].[FundID],[Funds].[FundTitle],[Funds].[AccountNo],[Funds].[Source],[DOE],[Amount],[Type]
    FROM [DonUnReg] INNER JOIN
    [Funds] ON [DonUnReg].[FundID] = [Funds].[FundID]
    Where DOE = DOEparms() AND Type = 3;

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You can never use the query itself in the control source. You could refer to a field in the query if the query was the record source of the form/report. You could use a DSum() on the query in a textbox.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    You can never use the query itself in the control source
    Ah yes, of course.............. DUH!

    The demands of the app sort of obscured my thinking, but you have awakened me with the use of DSum and the criteria facilities within, problem solved.
    Code:
    =DSum("[Amount]", "FundDonations", "[Type] = 1")  '2,3,...........n, etc

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Rather than multiple DSum()'s, you might consider a totals query that sums by type and use a subform/subreport based on that to display the results. More dynamic.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 10 Access 2013 32bit
    Join Date
    Feb 2011
    Posts
    1,919
    That's essentially what I was trying to do here:
    Click image for larger version. 

Name:	004.jpg 
Views:	5 
Size:	23.3 KB 
ID:	42176
    The block shown above is a Sub-Report. Each of the three values "Check", "Cash" and "Direct" were converted per your suggestion to use DSum. The totals were as you suggest with your last post.

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

Similar Threads

  1. Replies: 4
    Last Post: 08-09-2017, 12:06 PM
  2. Convert Union Query to non-union help
    By Ekhart in forum Queries
    Replies: 2
    Last Post: 01-10-2017, 03:39 AM
  3. Replies: 3
    Last Post: 08-11-2014, 10:14 AM
  4. Replies: 3
    Last Post: 10-02-2011, 06:47 PM
  5. Date function within a Union Query
    By pmplyons in forum Programming
    Replies: 2
    Last Post: 08-24-2011, 11:33 AM

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