Results 1 to 8 of 8
  1. #1
    BLFOSTER is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2013
    Posts
    68

    Sum or Dsum or........VBA

    How do I reference the current recordset on a CONTINUOUS form and "Sum" the wage field in this recordset based on criteria?



    So on Form Current:
    Mytextbox = Dsum("wage", CURRENT RECORDSET, "MyField = 'xxx'")

    My intention is to compare average wage on employment of clients belonging to 2 separate agencies.

    The recordset changes based on button pushed by user.

    Need the average wage to change according to current recordset.

    I have written several expressions to average wage, but since the recordset is on a continuous form, the average wage result is based on whichever agency appears at the top of the selected list. I have expressions to count instances of each agency in the recordset. I need to "sum" the wage field for each agency. I then have expressions to divide for average wage of each agency.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    Domain aggregates do not work on the form's recordset, they must reference a table or query object.
    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
    BLFOSTER is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2013
    Posts
    68
    hmmm....other options? I have tried "sum" but don't know the syntax.

    Thank you!

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    Did you try Sum or Avg expressions in textboxes in the form header or footer section?

    Did you say the form is filtered by agency?

    The DSum (or DAvg, DCount, etc) would be like:

    Dsum("wage", "tablename", "[Agency] = 'agency name'")

    However, that will not consider other filtering on the form, such as a date.
    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.

  5. #5
    BLFOSTER is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2013
    Posts
    68
    Yes, I tried those. The problem is the changing recordset of the continuous form. The form is not filtered by agency so all functions/expressions I have tried are performed for the agency who lands at the top of the list. I need the expressions to pick out the records that belong to each agency and sum or average the wage in those records separately. Right now I am working on 2 subreports in the header of the continuous form whose recordsources change to the same as the form on Current, thinking I can isolate each agency that way and add a sum or average function to the subreports footer but no luck so far!
    Getting "syntax error in "from" clause message - have no idea if this would ever work or not but DO hate to give up
    EXAMPLE:
    Forms!FORM2H!AvgR1.Report.RecordSource = "SELECT * FROM Forms!FORM2H!Form3H!.RecordSource " _
    & "WHERE [Expr5]='xyz'"

  6. #6
    BLFOSTER is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2013
    Posts
    68
    I figured it out....just had to write expression on the form right! Simple fix, but sure beat my head against the wall about it. Thanks for your help!

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    If the form is not filtering on agency, then form header/footer textbox:

    =Sum(IIf([Agency]="xyz",[Wages],0))

    Is that what you did?
    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
    BLFOSTER is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2013
    Posts
    68
    yes, exactly! I don't know why I didn't try that order of events earlier...smh

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

Similar Threads

  1. Dsum Help?
    By Ragin_roider in forum Queries
    Replies: 5
    Last Post: 03-19-2012, 03:10 PM
  2. Help with Sum and DSum
    By objNoob in forum Reports
    Replies: 5
    Last Post: 12-05-2011, 01:55 AM
  3. how to format the dsum value?
    By polis in forum Queries
    Replies: 7
    Last Post: 09-06-2011, 04:52 PM
  4. How do I use the DSum
    By Ironclaw in forum Access
    Replies: 1
    Last Post: 08-25-2010, 07:35 AM
  5. Help with dsum
    By bjsbrown in forum Reports
    Replies: 6
    Last Post: 02-06-2010, 09: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