Results 1 to 8 of 8
  1. #1
    tagteam is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    486

    Field to show total from a group of records

    I have a repairs table and I would like to show the total repairs to a car when that car is pulled up in the database. I know it is not suggested to have a calculated field in the table so what is the best way to do this.



    I can create a query that will only pull records for that car based on the car id but I am not sure how to get the total to appear in an unbound field. I have created a report that pops up to show the line item repairs and then shows a total but I would like a field that just shows a total and you dont have to click a button to open a query or report.
    Thanks

  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
    A DSum() would be one way, with the appropriate criteria:

    DLookup Usage Samples
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    tagteam is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    486
    Thanks for the input. I have tried

    =DSum([Net Charge],[t_Repair],"Criteria = " & [Forms]![f_railcars]![railcarid]=[t_Repair].[railcarID])

    Where Net Charge is the field i want to sum, t_repair is the table that Net Charge is in

    I am trying to show the total in an unbound field on the form f_railcars and so used the part at the end to try to say. Sum Net Charge from the table t_repair where the current railcarID from the form f_railcars is equal to the railcarID in the table t_repair

    However, I am just getting the standard #Name? and no data.

    I tried to follow this as the base example DLookup("FieldName", "TableName", "Criteria = " & forms!FormName!ControlName)

  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
    Criteria would be the name of the field the criteria is to be applied to.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    tagteam is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    486
    ok, so i have simplified it to

    =DSum([Net Charge],[t_Repair],"[forms]![f_railcars]![railcarid]=[t_Repair].[railcarID]")

    sum Net Charge from the table t_repair where the current railcarid = railcar id in the repair table but it still does not work

    I also tried putting it in a query and specifying an ID
    RepairTotal:dsum("Net Charge","t_repairs", "railcarID=4")

    but i get a VBA syntax error and i tried the id from the railcar and the repairs table. I must not be understanding this quite right.

  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,521
    The first is wrong; try this for the second:

    RepairTotal:dsum("[Net Charge]","t_repairs", "railcarID=4")

    railcarID has a numeric data type in the table?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    tagteam is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    486
    Thank you for the help, I was able to get it to work by using

    =DSum("[Net Charge]","t_Repair","RailcarID = " & [Forms]![f_Railcars]![railcarid])

    Apparently Access is a little finicky about where to put the [] and ""

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help. The brackets are required because of the inadvisable space in the field name.
    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: 2
    Last Post: 06-21-2012, 07:40 PM
  2. Replies: 2
    Last Post: 05-21-2012, 08:33 AM
  3. Group by Level2 BUT Total by Level3
    By goodguy in forum Reports
    Replies: 3
    Last Post: 10-05-2011, 08:54 AM
  4. Replies: 1
    Last Post: 03-15-2007, 03:38 PM
  5. Lookup or list field: how Do I not show all records
    By scott munkirs in forum Forms
    Replies: 4
    Last Post: 04-13-2006, 12:44 PM

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