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

    Expression Builder Syntax Problem

    Hi I have an expression duilder syntax problem.



    I'm trying to calculate the total amount spent on an event in a subform based on the main form record. Here is the code I have written:

    Code:
    =Nz(DSum(Forms![Donations subform]![AmountPaid],[PaymentsReceived],"[PaymentsReceived]![DonerRegID]=" & Nz([Donation ID] and Forms![Donations subform]![DonationType] = "Fund Raising Event",0)),0
    It's probably simple but your help is much appreciated.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Can't use domain aggregate functions (DSum, DAvg, etc) with references to form and form controls as the data source. Domain aggregate functions must reference tables/queries and fields as data source. Maybe you want:

    =Nz(DSum("AmountPaid", "PaymentsReceived", "DonerRegID=" & [DonationID] & " AND DonationType='FundRaisingEvent'")

    Use query aggregate functions (Sum, Avg, etc) in queries and on forms/reports to do aggregate calcs with the query or form/report RecordSource as data source. Set the subform as Continuous and in textbox in form footer: =Sum([AmountPaid])

    However, aggregate calcs are best done in reports.

    If you want to provide db for analysis, follow instructions at bottom of my post.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    maxmaggot is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Location
    Ireland
    Posts
    91
    Thanks so much. It says one parethisis missing. Can't spot it. Any idea? Thanks again. Cleared up alot of confusion for me.

  4. #4
    maxmaggot is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Location
    Ireland
    Posts
    91
    Found it. thanks so much.

  5. #5
    maxmaggot is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Location
    Ireland
    Posts
    91
    Can I PM you the db to look at the expression on the Funds page at the left. It contains hospital records for our leukaemia charity so I don't want it public

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    You can upload the db to a fileshare site such as Box.com then pm me the link.

    Or make copy and remove confidential data and attach to post.

    Don't I already have the db from other thread? Exactly which form is involved in the issue?

    Don't know if you are going to make deadline. I'm about to go to bed.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    The PaymentsReceived table is actually saving the EventType code, not the description (because of combobox lookup). So the criteria must be the code not the description.

    =Nz(DSum("AmountPaid","PaymentsReceived","DonerReg ID=" & [Donation ID] & " AND EventType=2"))

    That gets rid of the error in textbox but no data shows. Okay, think I found source of issue. The Lookups for EventType and DonationType in PaymentsReceived appear to be swapped. Instead of saving the EventType code in EventType field, it is saving the DonationType code. EventType code is saved in the DonationType field.

    An odd thing is I can find only one record for DonerID 294 in PaymentsReceived even though the form shows 2.

    Also, change expressions for Individual calcs:

    =Nz(DSum("[TotalPrice]","[ChristmasCards]","[DonerRegID]=" & Nz([Donation ID],0)),0)

    =Nz(DSum("[NumOrdered]","[ChristmasCards]","[DonerRegID]=" & Nz([Donation ID],0)),0)
    Last edited by June7; 06-14-2013 at 03:13 AM.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    maxmaggot is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Location
    Ireland
    Posts
    91

    Brilliant

    Can't thank you enough for your work. Must have driven you mad too

    Thanks so much
    Kind Regards
    Karl

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

Similar Threads

  1. Replies: 2
    Last Post: 11-20-2012, 03:21 AM
  2. Expression builder help
    By jigg14 in forum Forms
    Replies: 1
    Last Post: 03-19-2012, 09:47 AM
  3. Expression Builder Problem
    By benthamq in forum Forms
    Replies: 3
    Last Post: 10-07-2011, 01:02 PM
  4. Expression builder
    By PJ_d_DJ in forum Access
    Replies: 2
    Last Post: 02-24-2011, 03:38 AM
  5. Expression Builder
    By mistaken_myst in forum Access
    Replies: 2
    Last Post: 05-07-2008, 01:30 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