Results 1 to 6 of 6
  1. #1
    maxmaggot is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Location
    Ireland
    Posts
    91

    Calculated Field on Form To return YTD totals

    Hi folks,
    I have a calculated field on an MS access 2010 form and I am trying to calculate the YTD total. I have generated the following SQL for this field

    = SELECT Sum(Donations.Amount) AS SumOfDonations
    FROM Donations
    GROUP BY DatePart("yyyy",[DatePaid])
    HAVING (((DatePart("yyyy",[DatePaid]))=DatePart("yyyy",Date())));



    I keep getting a syntax error about the subquery parenthesis and I cannot figure it out.

    Any help?

  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,641
    You can't have SQL as the control source. Try a DSum().
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    maxmaggot is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Location
    Ireland
    Posts
    91
    Thanks Paul. Just figured that out. Created a query to calculate the answer which looks like

    Field: Amount
    Table: Donations
    Total: Sum

    Field: DatePart("yyyy",[DatePaid])
    Total: Group By



    then used

    =DLookUp("[SumOfAmount]","[Donations - YTD Amount Total]")

    in the calculated field

  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,641
    Happy to help, though I would have avoided the extra query and used DSum(). Welcome to the site by the way!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    maxmaggot is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Location
    Ireland
    Posts
    91
    I've said to myself I should do this properly from the start and tried using DSUM(). I'm getting a #Type error.

    =DSum("[Amount]","[Donations]") & DLookUp(DatePart("yyyy","[DatePaid]"),"[Donations]",DatePart("yyyy",Date()))

    Thanks for your time

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    It would be a single formula. See if this helps:

    http://access.mvps.org/access/general/gen0018.htm

    if not, can you post the db here?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 8
    Last Post: 09-27-2012, 11:25 AM
  2. Replies: 3
    Last Post: 04-01-2012, 01:40 PM
  3. Calculated Field in continuous form
    By doobybug in forum Forms
    Replies: 2
    Last Post: 11-15-2009, 08:54 AM
  4. Calculated and send to totals. Question
    By castellano in forum Programming
    Replies: 1
    Last Post: 06-12-2009, 12:40 PM
  5. Replies: 1
    Last Post: 02-05-2009, 04:53 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