Results 1 to 5 of 5
  1. #1
    bbrazeau is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2011
    Posts
    101

    Allen Brownes Inventory code


    I used Allen Brownes code to make an Inventory example where the "On Hand" is calculated. I then wanted to tried and make the Invoice side of it work for Products instead of just parts. (Products are assemblies of parts)
    So I wrote a query to parse the part qty per product and the product qty per Invoice then multiply them together in an expression "LIPP1" (see code) I then went to SQL mode and copied the SQL statement. Then went to the 'Get the quantity used since then.' section of his code and replaced his strSQL with mine. I then tried to used his syntax for Sum and criteria to atempt to get the total parts used. I get runtime error 3075 with "missing operator". Could anyone tell me if they see the problem or even if I'm going about this the right way? I know if I can Sum the LIPP1 parameter of my query it works out mathimatically. I just can't get it to work in code.

    strSQL = "SELECT Sum (tblInvoice.InvoiceID, tblInvoiceDetail.ProductID, tblInvoiceDetail.Quantity " & _
    " AS tblInvoiceDetail_Quantity, tblProductDetail.PartID, tblProductDetail.Quantity AS tblProductDetail_Quantity, " & _
    " [tblInvoiceDetail_Quantity]*[tblProductDetail_Quantity] AS LIPP1) As QuantityUsed " & _
    " FROM (tblProduct INNER JOIN tblProductDetail ON tblProduct.[ProductID] = tblProductDetail.[ProductID]) INNER JOIN " & _
    " (tblInvoice INNER JOIN tblInvoiceDetail ON tblInvoice.[InvoiceID] = tblInvoiceDetail.[InvoiceID]) ON tblProduct.[ProductID] = tblInvoiceDetail.[ProductID] " & _
    " WHERE ((tblProductDetail.PartID)= " & lngPart & ")"

    Set rs = db.OpenRecordset(strSQL) Hangs on this line, but problem is in the SQL statement above.

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You don't (shouldn't ) sum the tblInvoice.InvoiceID, tblInvoiceDetail.ProductID or tblProductDetail.PartID fields.


    Try adding a Debug.Print statement strSQL statement befort the "Set rs = ... " line
    Set a breakpoint on the "Set rs = ... " line
    Copy the text from the immediate window and paste it into a new query (SQL view) to test it.

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Certainly should not include all the fields in one Sum expression. Sum and other aggregate functions are used in GROUP BY (Totals) queries. Use the query builder to help construct the sql statement.

    Or consider a report that uses Grouping & Sorting features with aggregate calcs in footer sections.

    What do you want to do with the recordset 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.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Further to comments from June and Steve, I suggest you look at some SQL examples at http://www.w3schools.com/sql/sql_select.asp

    Good material on Sum and Group etc.

  5. #5
    bbrazeau is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2011
    Posts
    101
    Thanks for all the help on this. In the end the solution I came to was to simply base my recordset on a query instead of trying to extract it from the tables. The query "OrdProdPart" has a calculated field "TotalPartsUsed" which gives the total parts used by each product in every order times the number of products ordered. When you Sum this total where Part = Part selected in a combobox, it gets the total parts used in all orders by every Product that uses that part. When you subtract this from all parts acquired or all parts acquired after the optional StockTakeDate it returns parts "OnHand". The basis of my error was using a method I seen sugested before for building an SQL statment that said: write a query to gather the information you need then switch to SQL mode and copy the SQL statment. Then paste it in your code and it should be close barring some syntax adjustments. In this case it did not work.

    strSQL = "SELECT Sum (TotalPartsUsed)As QuantityUsed " & _
    " FROM OrdProdPart WHERE ((OrdProdPart.Part= " & lngPart & ")"

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

Similar Threads

  1. Allen Browne GoHyperlink Module help
    By kagoodwin13 in forum Modules
    Replies: 3
    Last Post: 06-10-2013, 07:43 PM
  2. Allen Browne Ranking Sample?
    By kwooten in forum Queries
    Replies: 1
    Last Post: 05-17-2013, 04:42 PM
  3. Replies: 1
    Last Post: 02-21-2013, 12:18 AM
  4. VB Code for Access DB for Inventory Tracking with FIFO
    By rao.gnaneswara in forum Programming
    Replies: 16
    Last Post: 01-19-2013, 11:59 PM
  5. Need a little help with Allen Browne code
    By NewtoIT in forum Programming
    Replies: 16
    Last Post: 05-09-2012, 04:50 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