Microsoft Access - I'm having an issue using DSum() in a query and I cannot figure out the solution.

Asked By mark collins on 20-Jun-12 04:50 PM
Earn up to 40 extra points for answering this tough question.
I'm not a programmer by any means, I use the design view in Access to get what I need done so I'm getting lost trying to figure out how to write this DSum function...

The setup so far... linking two queries, Launch_NPI020 & Receiving020.  Taking all of the data from the Launch query and adding receipt quantity.  The Sold Qty from the Launch query is what I need to get as a running sum by date... The criteria I need to sum by are - Launch_NPI020.Carrier, Launch_NPI020.Model, Launch_NPI020.Color, Launch_NPI020.MonDate

Mondate is the date field... monday date of each week.


Here is the code so far... everything works but the DSum...
SELECT Launch_NPI020.Year, Launch_NPI020.Week, Launch_NPI020.WeekLookup, Launch_NPI020.MonDate, Launch_NPI020.Carrier, Launch_NPI020.Model, Launch_NPI020.Color, Launch_NPI020.SoldQty, IIf([Receiving020]![SumOfDelvyQty] Is Null,0,[Receiving020]![SumOfDelvyQty]) AS RecQty,

DSum("SoldQty","Launch_NPI020","Carrier = " & [Launch_NPI020]![Carrier]) AS TotalSold

FROM Launch_NPI020 LEFT JOIN Receiving020 ON (Launch_NPI020.Color = Receiving020.Color) AND (Launch_NPI020.Model = Receiving020.Model) AND (Launch_NPI020.Carrier = Receiving020.Carrier) AND (Launch_NPI020.WeekLookup = Receiving020.WeekLookup);

......

I keep getting a syntax error.  Do I need to force-define some of these field properties?  If so, how do I do this?  I saw somewhere to use a "Dim" function, but that just confused me.

Please help and thank you in advance

Desired output:

Year      Week   WeekLookup     MonDate            Carrier       Model       Color    SoldQty       RecQty      TotalSold
2012         18        201218          4/30/12               V              x75             B           10                7                 10
2012         18        201218          4/30/12               A              Y20             R           20                10               20 
2012         18        201218          4/30/12               V              x75             Z           30                8                 30 
2012         19        201219          5/07/12               V              x75             B           30                7                 40 
2012         19        201219          5/07/12               A              Y20             R           10                7                 30 
2012         19        201219          5/07/12               V              x75             Z           70                7                 100 


wally eye replied to mark collins on 21-Jun-12 10:50 AM
Could you use a GroupBy query?

SELECT Launch_NPI020.Year, Launch_NPI020.Week, Launch_NPI020.WeekLookup, Launch_NPI020.MonDate, Launch_NPI020.Carrier, Launch_NPI020.Model, Launch_NPI020.Color, Launch_NPI020.SoldQty, IIf([Receiving020]![SumOfDelvyQty] Is Null,0,[Receiving020]![SumOfDelvyQty]) AS RecQty, Sum(Launch_NPI020.SoldQty) AS TotalSold

FROM Launch_NPI020 LEFT JOIN Receiving020 ON (Launch_NPI020.Color = Receiving020.Color) AND (Launch_NPI020.Model = Receiving020.Model) AND (Launch_NPI020.Carrier = Receiving020.Carrier) AND (Launch_NPI020.WeekLookup = Receiving020.WeekLookup)

GROUP BY Launch_NPI020.Year, Launch_NPI020.Week, Launch_NPI020.WeekLookup, Launch_NPI020.MonDate, Launch_NPI020.Carrier, Launch_NPI020.Model, Launch_NPI020.Color, Launch_NPI020.SoldQty, IIf([Receiving020]![SumOfDelvyQty] Is Null,0,[Receiving020]![SumOfDelvyQty]) AS RecQty;

Then, on your report you can use the running sum to get your Total Sold column.
mark collins replied to wally eye on 21-Jun-12 11:24 AM
Unfortunately I do not think the group by will do anything to help.  It is already grouped in previous queries.  For each week, there is only one unique Carrier/Model/Color.  Grouping will give me the exact same information that I started with.
wally eye replied to mark collins on 21-Jun-12 09:08 PM
Short of using some VBA to build an intermediate table, your best option would be to sort on all identifying fields and create a report with running totals that breaks between groups to restart the running total.
help
Please can someone tell me what wrong with my dsum = dsum("[Amount]", "Sales Analysis", "SalesgroupingField = "Customer No" & " CbMonth" = Month" & " "Type = "Actual") Access Discussions SalesgroupingField (1) CustomerNo (1) CbMonth (1) Month (1) Dsum (1) Day (1) Assuming CustomerNo and Month are both numeric variables, it should be dsum("[Amount]", "Sales Analysis", "SalesgroupingField = " & _ Customer No & " AND CbMonth = " & Month & "AND Type = 'Actual'") And, actually since it is a reserved word. Note the single quotes around Actual. - - Doug Steele, Microsoft Access MVP http: / / www.AccessMVP.com / DJSteele (no e-mails, please!) Alan, Because the syntax you given is "off" by quite a bit, it is hard toll what elements of the DSum are field names or field values. . . and what field types might be involved. We can
my formula is going wrong please DataBase can some please tell what wrong with my dsum = DSum("[Amount6a6fs]", "[Sales Analysis]", "[Posting Date Period] = '" & [cbMonth] & "' And [Revenue Stream Division] = 'Postage'" And "'([customer no no] = 'C00785' or [customer no] = 'C01388' or [customer no] = 'IC0003' or [customer no] = 'C01317')") thanks Access Discussions Revenue Stream Division Postage (1) Revenue Stream Division 3D (1) Bit (1) Sales Analysis expect? One thing could be [Posting Date Period]. What type is it? - - Groeten, Peter http: / / access.xps350.com its kind of work but the last part does not p compile as myForm!cbMonth instead of [cbMonth] (change myForm to your form's name) This should work = DSum("[Amount6a6fs]", "[Sales Analysis]", And [Revenue Stream Division] = 'Postage' And [customer no] IN ('IC0008', 'C01105', 'C00785 an & missing in: . . . [Revenue Stream Division] = 3D 'Postage'" And "'([customer no] = 3D. . . Groeten, Peter http: / / access.xps350.com = DSum("[Amount6a6fs]", "[Sales Analysis]", "[Posting Date Period] = '" & [cbMonth] & "' And [Revenue Stream Division] = 'Postage' And ([customer no customer no] = 'IC0003' or [customer no] = 'C01317')") A little bit easier to read would be = DSum("[Amount6a6fs]", "[Sales Analysis]", "[Posting Date Period] = '" & [cbMonth] & "' And [Revenue Stream Division] = 'Postage' And [customer no
Hello, I have a query with two Dsum functions and i want to join them (x+y) in the same query. I get the result of just one of them , way ? thank you - - תודה רבה Access Discussions SumXandY (1) Dsum (1) החביב (1) תודה (1) יריב (1) רבה (1) hi, יריב החביב schrieb: SumXandY DSum() + DSum() Not sure, without seeing your queries SQL statment. Is one of your DSum() returning 0 or Null? mfG - -> stefan <- - keywords: Joining, , two, Dsum description: Hello, I have a query with two Dsum functions and i want to join
= DSum("[Amount]"-"[Amount2]", "Tabel1", " [CustomerNo] = " & [CustomerNo]) Have this on my report my report fives me this error C00002 1000 2000 #error Please can some tell me why i'm getting error?? Access Modules DAO Discussions Report (1) CustomerNo (1) Fives (1) DSUM (1) The expression you are summing must be provided to DSum as a single string argument. Try this: = DSum("[Amount]-[Amount2]", "Tabel1", " [CustomerNo] = " & [CustomerNo]) It is not clear to me, though, whether that expression need for the controlsource of your [result] text box is: = [Amount1]-[Amount2] - - Dirk Goldgar, MS Access MVP Access tips: www.datagnostics.com / tips.html (please reply to the newsgroup) keywords: ERROR#, DSUM description
I recently upgraded to Access 2007. I tried using HELP to search on a specific statement and was unable to need is the VBA Language Reference for 2007. Can anyone offer any suggestions? Jack Cannon Access Discussions Access Options Trust Center Privacy Options (1) David W. Fenton (1) Access 2007 (1) Office (1) Teresa Hennig Armen Stein (1) Jack Cannon Arvin Meyer (1) DSUM (1) VBA (1) I have had the same difficulty. I use 2 sources, first Access 97 help, which has an excellent, albeit for Access 2007 incomplete help file. And the second source is Access 2007 VBA Programmer's Reference
Please help! I finally got the dsum to give me the correct answer. Now when I open the form I get "The Here is what I have in the control source in my unbound text box: = nz(DSum("TotalPriestCompensation", "tblActualExpense", "FiscalYear = 'Fiscal 12 July 11 to June 12'AND ParishNumber = 304")) I plan in a string and integer variables to isolate the problem further. Something like this: = nz(DSum("[TotalPriestCompensation]", "[tblActualExpense]", "[FiscalYear] = '" & ddlFiscalYear.value & "' AND [ParishNumber] = " & ddlParishNumber.value), 0) The problem could stem from but the best thing to do is work your backwards. Sincerely, Maurice Maglalang keywords: Microsoft Access DSUM, DSUM, FiscalYear description: DSUM finally working but. . . . . . Please help!I finally got the dsum to give
tb1: = dsum(. . . . .) tb2: = dsum(. . . . .) etc. tbTot: = nz(tb1, 0)+nz(tb2, 0)+nz(tb3, 0). . . . tbTot calculates too fast the series, after all the rest are done. Ideas? Probably simple. Thanks in advance. - - Jim Access Forms Discussions TbTot (1) Catches (1) Dsum (1) Tb1 (1) Tb3 (1) Tb2 (1) Hi JimS, you can try using vba to preferably the event which causes the values for tb1, tb2 . . . to change. Jeanette Cunningham MS Access MVP - - Melbourne Victoria Australia The event that causes those other text boxes to change is it would be just as quick to calc, and therefore miss the postback from the dsum calcs. I guess I am just going to have to make the control source equal to = DSum(. . .)+DSum(. . .), etc. That means I recalc all those DSums twice every time one of them is
Quick Question - I am using the DSUM function to pull data from a table into a report in access 2003. Can you use the DSUM function to pull data from a query? Also, I noticed that there is some lag time when using the DSUM function - is there a faster way to pull data from a large data table? Thanks for your help. Brennan Access Queries Discussions Report (1) Brennan (1) DSUM (1) Sums (1) Yes, you can use DSum against a query - usually. If the query is a parameter query then where you input
I am using the DSUM function, with query fields as inputs. The inputs are numbers. When I use the DSUM function on them it returns values as text - not numbers. There can be null values in the fields that DSUM is working off of. Other than going back and making the inputted nulls all zeros is there a work around to get the values from DSUM as numbers and not text? Thanks. Access Getting Started Discussions DSUM (1) QryGREEN (1) Blue_All (1) RowNum (1) IDen_Yellow_All (1) IDen_Purple_All (1) TestID (1) FredNum (1 doesn't normally happen that way. My guess would be that it is not the DSUM that is returning a text value, but that something is changing the returned value. Can
Access 2003 Hallo, wie ist es innerhalb von Access m?glich - z.B. SQL - nach einem Feld ?ber mehrere Tabellen abzufragen ? In jeder Tabelle abfragen. ?ber select PC from * funktioniert es nicht. Danke f?r Eure Hilfe. MfG Albe Access Discussions CurrentDb.TableDefs (1) CurrentDb.QueryDefs (1) DoCmd.DeleteObject (1) Access 2003 (1) DeinSteuerelementImUFo (1) VBA (1) Debug.Print (1) VBAGru (1) Hallo Alwin, Beck, Alwin from Tabelle2 union select PC from Tabelle3 union select PC from Tabelle4 Gru? Gunter - - _ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ _ Access FAQ: http: / / www.donkarl.com home: http: / / www.avenius.com - http: / / www.AccessRibbon.de http auch ? Danke Gru? Albe Hallo Alwin, Beck, Alwin schrieb folgendes: . . . IMO Nein. Gru? Gunter - - _ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ _ Access FAQ: http: / / www.donkarl.com home: http: / / www.avenius.com - http: / / www.AccessRibbon.de http eaglesnest-bb.com / Hallo Lupus, Lupus Goebel schrieb folgendes: . . . Klar ;-) mittels VBA Gru? Gunter - - _ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ _ Access FAQ: http: / / www.donkarl.com home: http: / / www.avenius.com - http: / / www.AccessRibbon.de http