Results 1 to 4 of 4
  1. #1
    epb is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jul 2012
    Location
    Near Chicago
    Posts
    36

    DSum not coming up with the correct Total

    Hello, I have an Inventory DB Table called [EngData] that has a subform table called [Inventory]. I have in the subform a calculated text box that Sums three columns, StockQtyMade, StockQtySold and StockQtyShrink. This works perfectly.



    On the Main form I have a calculated text box that references the subform calculated field. This also displays correct info.

    On another Form I wanted other users to see the total stock on hand by using a calculated field called PullTotalQty. This is set by using DSum(...). The only problem is that the DSum(...) keeps giving totals that are not accurate. Sometimes the quantity is a few pieces less then the correct amount and in other cases the qty is many times what it should be. Whatever the amount in error it is consistent each time a particular record is displayed. I have tried many things to get this to work but nothing has fixed the issue. I have also tried changing the query and nothing works. Changing the query and using the [Inventory] table in the DSum domain gives a different wrong quantity.

    Here is the code: I reduced the code down to one column to be summed (StockQtyMade) just to see if I could get that working first. I will add the other two columns later. for testing purposes I am only looking at the StockQtyMade amounts.

    Me.PullTotalQty.Value = DSum("[tblInventory subform].[Form].[StockQtyMade]", "[SumStockQuery]", "[tblInventory subform].[Form].[PartID]= " & Me.[ID])
    Here is the SumStockQuery SQL:

    SELECT Inventory.TransactionID, Inventory.PartID, Inventory.PrintNo, Inventory.StockRev, Inventory.StockQtySold, Inventory.StockQtyMade, Inventory.StockQtyShrink, Inventory.StockQtyXIncomplete, Inventory.StockLoc, Inventory.TransactionDescription
    FROM Inventory
    WHERE (((Inventory.TransactionDescription)<>"xNextOP"))
    ORDER BY Inventory.TransactionID DESC;
    Any Ideas on why the totals are incorrect??

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,610
    Perhaps you need:

    Me.PullTotalQty.Value = DSum("[StockQtyMade", "SumStockQuery", "PartID= " & Me.[ID])
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    John_G is offline VIP
    Windows XP Access 2003
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi -

    Bob is right (except for a missing "]" !) -

    When you are using DSum, the field being summed should (Must?) be a part of the table/query you are drawing the data from, in your case "SumStockQuery". A form control is not part of the query, although it can *display* a field from the query.

    The same is true for the criteria part - it should reference a field in the same table/query, not a form field, because if the form control does not have the right data source (from the table/query), who knows what you would get.

    I'm surprised it doesn't give you an error, but I think Access is trying to figure out what you want, but doesn't get it right.

    John

  4. #4
    epb is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jul 2012
    Location
    Near Chicago
    Posts
    36
    Thank you, That has solved the issue!

    I appreciate it. I spent hours trying to figure this out. Always something you learn through hard knocks.

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

Similar Threads

  1. Replies: 4
    Last Post: 03-05-2012, 10:20 AM
  2. criterium coming from another query
    By khhess in forum Queries
    Replies: 2
    Last Post: 02-11-2012, 02:28 PM
  3. #NAME? Error keeps coming back
    By tharless in forum Access
    Replies: 24
    Last Post: 02-09-2012, 03:10 PM
  4. Replies: 9
    Last Post: 06-26-2011, 09:14 PM
  5. not correct running total in group
    By cmk in forum Reports
    Replies: 1
    Last Post: 12-06-2006, 05:56 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