Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 38
  1. #16
    Join Date
    Apr 2017
    Posts
    1,687


    Quote Originally Posted by writeprivate View Post
    Hi there Avril - thanks so much for replying and taking the time to help me.

    1. Just so I understand, are your suggestions relating to the first database that I submitted OR the one Orange has added?
    To post #1.
    2. Would it be possible (I know this is a big ask) for you to download that sample db, make the changes and repost here. It would be amazing to have two working options and then I can have reports and form view
    Sorry, but I don't have Access available currently.

  2. #17
    writeprivate is offline Advanced Access Coder
    Windows 10 Access 2021
    Join Date
    Feb 2023
    Posts
    42
    @Orange

    Hi Jack

    I have fully integrated with my existing system and all works well except for one thing.....

    The reports only show an output where there has been a sale record as well as a purchase record. This makes sense for the first 5 reports as they are calculating profit etc. But the last report (which is really vital) should show the quantity in stock even if there has been no sale

    So in short, the report "Stock Value Report on Fifo Basis" only shows results for those stock items for which there has been a purchase AND and sale - therefore, if I have purchased 10 Microsoft shares but not sold any, then the report is blank and will not show the units available

    This "Stock Value Report on Fifo Basis" report is based on the QryStockAvailable query which in turn is based on the QryStockAvailableSub query (see screenshot below)

    I have tried to amend the expression to take account of an isnull situation for TSale (where the yellow highlight is) but I think this isn't working because the recordset is already Null as it is based on QryTotalSales which is at the root of the issue. I have also tried to update the QryTotalSales query but cannot work out what to do. As a last ditch attempt, I tried to amend the join properties of the QryStockAvailable query to show all the QryStockAvailableSub and only the QryTotalSales records which match but it is causing an 'Ambigiuous Join" error.

    Please could you help? I cannot get this to work

    Thanks

    UPDATE: Please note you may notice that i have changed some fieldnames from the version you have - but this does not affect the error - I have checked the same behaviour occurs with the orginal version - you just need to delete sales for a particular product and the report will then not show any stock available

    Click image for larger version. 

Name:	output10.jpg 
Views:	44 
Size:	71.4 KB 
ID:	49681

  3. #18
    writeprivate is offline Advanced Access Coder
    Windows 10 Access 2021
    Join Date
    Feb 2023
    Posts
    42
    Hi Jack - as I'm new to the board, I thik I made a mistake posting to the end of the thread rather than directly to your last comment. Please could you take a look at the last post on page 2. I have a groud to a halt error and could really appreciate your insights. Thanks

  4. #19
    orange's Avatar
    orange is online now Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,742
    I think I have a workaround, but you'll have to do some checking/verifying with your data.

    Here is some sql that should identify QtyAvailable for each Product whether or not they have had sales.
    In fact it deals with Sales, and then adds in those that had NO sales to identify total QtyAvailable and then TotalValue of Available Stocks.

    The first part is what currently exists. After UNION,is the part that deals with Products that have had no sales.

    Code:
    SELECT QryStockAvailableSub.BatchNo, QryStockAvailableSub.PDate, Products.ProductDesc,
    QryStockAvailableSub.PQty AS [Purchased Qty], QryStockAvailableSub.PPrice
    , IIf([TSale]>[popn],[pruntot]-[TSale],[pqty]) AS AvailableQty
    , [AvailableQty]*[PPrice] AS StockValue
    FROM Products INNER JOIN (QryTotalSales INNER JOIN QryStockAvailableSub ON
     QryTotalSales.Product = QryStockAvailableSub.Product) ON 
    Products.ProductId = QryTotalSales.Product
    WHERE (((QryStockAvailableSub.PDate)<=[forms]![frmreports]![TDate]) AND 
    ((QryStockAvailableSub.PRunTot)>[TSale]))
    
    UNION 
    
    SELECT Purchase.BatchNo, Purchase.PDate, Products.ProductDesc, Purchase.PQty AS PurchasedQty
    , Purchase.PPrice, Purchase.PRunTot AS AvailableQty
    , ([AvailableQty]*[PPrice]) AS StockValue
    FROM Products INNER JOIN (Purchase LEFT JOIN Sales ON
     Purchase.Product = Sales.Product) ON
     Products.ProductId = Purchase.Product
    WHERE  (Sales.Product Is Null AND 
    Purchase.PDate<=[forms]![frmreports]![TDate]);
    I named this query: QryStockAvailableWithAndWithoutSales

    You have to change the record source of the Report: StockReportOnFifoBasis

    From: QryStockAvailable

    TO : QryStockAvailableWithAndWithoutSales

    If you are unclear with this process, let me know, and I'll send a new database with the changes.

    It is important to test with some sample data before making this a permanent change.
    Last edited by orange; 02-13-2023 at 05:56 PM. Reason: Trying to make the SQL readable

  5. #20
    orange's Avatar
    orange is online now Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,742
    I think I have a workaround/fix, but you'll have to do some checking/verifying with your data.

    Here is some sql that should identify QtyAvailable for each Product whether or not they have had sales.
    In fact it deals with Sales, and then adds in those that had NO sales to identify total QtyAvailable and then TotalValue of Available Stocks.

    The first part is what currently exists. After UNION,is the part that deals with Products that have had no sales.

    Code:
    SELECT QryStockAvailableSub.BatchNo, QryStockAvailableSub.PDate, Products.ProductDesc, QryStockAvailableSub.PQty AS [Purchased Qty], QryStockAvailableSub.PPrice, IIf([TSale]>[popn],[pruntot]-[TSale],[pqty]) AS AvailableQty, [AvailableQty]*[PPrice] AS StockValue
    FROM Products INNER JOIN (QryTotalSales INNER JOIN QryStockAvailableSub ON QryTotalSales.Product = QryStockAvailableSub.Product) ON Products.ProductId = QryTotalSales.Product
    WHERE (((QryStockAvailableSub.PDate)<=[forms]![frmreports]![TDate]) AND ((QryStockAvailableSub.PRunTot)>[TSale]))
    UNION SELECT Purchase.BatchNo, Purchase.PDate, Products.ProductDesc, Purchase.PQty AS PurchasedQty, Purchase.PPrice, Purchase.PRunTot AS AvailableQty, ([AvailableQty]*[PPrice]) AS StockValue
    FROM Products INNER JOIN (Purchase LEFT JOIN Sales ON Purchase.Product = Sales.Product) ON Products.ProductId = Purchase.Product
    WHERE  (Sales.Product Is Null AND Purchase.PDate<=[forms]![frmreports]![TDate]);
    I named this query: QryStockAvailableWithAndWithoutSales

    You have to change the record source of the Report: StockReportOnFifoBasis

    From: QryStockAvailable

    TO : QryStockAvailableWithAndWithoutSales

    If you are unclear with this process, let me know, and I'll send a new database with the changes.

    It is important to test with some sample data before making this a permanent change.

  6. #21
    writeprivate is offline Advanced Access Coder
    Windows 10 Access 2021
    Join Date
    Feb 2023
    Posts
    42
    Quote Originally Posted by orange View Post
    I think I have a workaround/fix, but you'll have to do some checking/verifying with your data.

    Here is some sql that should identify QtyAvailable for each Product whether or not they have had sales.
    In fact it deals with Sales, and then adds in those that had NO sales to identify total QtyAvailable and then TotalValue of Available Stocks.

    The first part is what currently exists. After UNION,is the part that deals with Products that have had no sales.

    Code:
    SELECT QryStockAvailableSub.BatchNo, QryStockAvailableSub.PDate, Products.ProductDesc, QryStockAvailableSub.PQty AS [Purchased Qty], QryStockAvailableSub.PPrice, IIf([TSale]>[popn],[pruntot]-[TSale],[pqty]) AS AvailableQty, [AvailableQty]*[PPrice] AS StockValue
    FROM Products INNER JOIN (QryTotalSales INNER JOIN QryStockAvailableSub ON QryTotalSales.Product = QryStockAvailableSub.Product) ON Products.ProductId = QryTotalSales.Product
    WHERE (((QryStockAvailableSub.PDate)<=[forms]![frmreports]![TDate]) AND ((QryStockAvailableSub.PRunTot)>[TSale]))
    UNION SELECT Purchase.BatchNo, Purchase.PDate, Products.ProductDesc, Purchase.PQty AS PurchasedQty, Purchase.PPrice, Purchase.PRunTot AS AvailableQty, ([AvailableQty]*[PPrice]) AS StockValue
    FROM Products INNER JOIN (Purchase LEFT JOIN Sales ON Purchase.Product = Sales.Product) ON Products.ProductId = Purchase.Product
    WHERE  (Sales.Product Is Null AND Purchase.PDate<=[forms]![frmreports]![TDate]);
    I named this query: QryStockAvailableWithAndWithoutSales

    You have to change the record source of the Report: StockReportOnFifoBasis

    From: QryStockAvailable

    TO : QryStockAvailableWithAndWithoutSales

    If you are unclear with this process, let me know, and I'll send a new database with the changes.

    It is important to test with some sample data before making this a permanent change.
    Amazing, thanks. I'll test this tomorrow and get back to you. Much appreciated.

  7. #22
    writeprivate is offline Advanced Access Coder
    Windows 10 Access 2021
    Join Date
    Feb 2023
    Posts
    42
    Quote Originally Posted by writeprivate View Post
    Amazing, thanks. I'll test this tomorrow and get back to you. Much appreciated.
    Thank you so much.



    FEEDBACK ON NEW QUERY "withandwithoutsales"

    1. Works really well and now shows the stock of all products regardless if they have a sale - I am in awe of your hand-written SQL Union query

    2. As a result of the report now showing, I have discovered a separate bug (See Screenshot below) - if you only sell one unit, then the query (yours and the original) ignores that single unit sold and shows Available Quantity as everything purchased. FWIW, I think this might be because of:
    • the QuantityStockAvailable Qry expression criteria on Purchase Running Total needing to be > [TSale], or
    • the popn expression on the QryStockAvailableSub
    • I don't want to fiddle with these as I don't really understand what these do and don't want to shift a problem to elsewhere


    Click image for larger version. 

Name:	output13.jpg 
Views:	47 
Size:	100.3 KB 
ID:	49686


    A RELATED REQUEST IF POSSIBLE

    3. As an aside, is it possible to see a Union query in the design query grid view? I am trying to reuse the QryStockAvailableWithAndWithoutSales query elsewhere as "PortfolioHoldingQuery:
    • where the Portfolio table "id" is equal to [Forms]![frmPortfolios]![id]
    • the Portfolio table is connected to the QryStockAvailableSub query via the Sales table per the screenshot
    • I attached below the existing PortfolioHoldingQuery which I would need to update with the new withandwithout sales output.
      • Also attached is that SQL (apologies for the field name changes, please use your version and i can update)
      • Also attached is the general relationships diagram for context



    Click image for larger version. 

Name:	output12.jpg 
Views:	47 
Size:	104.7 KB 
ID:	49687

    Code:
    SELECT QryStockAvailableSub.batch_number, QryStockAvailableSub.purchase_date, Products.product_name, QryStockAvailableSub.purchase_quantity AS [Purchased Qty], QryStockAvailableSub.purchase_price, IIf([TSale]>[popn],[QryStockAvailableSub]![purchase_running_total]-[TSale],[purchase_quantity]) AS AvailableQty, [AvailableQty]*[purchase_price] AS StockValue, Products.product_symbol, Portfolios.idFROM Portfolios INNER JOIN (Sales INNER JOIN (Products INNER JOIN (QryTotalSales INNER JOIN QryStockAvailableSub ON QryTotalSales.fk_so_product_id = QryStockAvailableSub.fk_po_product_id) ON Products.product_id = QryTotalSales.fk_so_product_id) ON Sales.fk_so_product_id = QryStockAvailableSub.fk_po_product_id) ON Portfolios.id = Sales.sales_portfolio_id
    WHERE (((Portfolios.id)=[Forms]![frmPortfolios]![id]) AND ((QryStockAvailableSub.purchase_running_total)>[TSale]));

    Click image for larger version. 

Name:	output11.jpg 
Views:	49 
Size:	92.3 KB 
ID:	49690

  8. #23
    orange's Avatar
    orange is online now Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,742
    writeprivate,

    Here are a couple of graphics mentioned in PM.
    You can not attach files with a PM.

    Sample BatchAllocation of a singleunit /1 of Product.


    Click image for larger version. 

Name:	BatchAllocSingle.PNG 
Views:	50 
Size:	36.0 KB 
ID:	49704

    Revised frmReport with Check Available Product Button and Result

    Click image for larger version. 

Name:	Modified_frmReports to show ProductAvailability.PNG 
Views:	50 
Size:	31.3 KB 
ID:	49705

  9. #24
    writeprivate is offline Advanced Access Coder
    Windows 10 Access 2021
    Join Date
    Feb 2023
    Posts
    42
    Amazing - showing that single stock sale is such a big obstacle
    The current gross availablility is a lovely touch. Thanks as always.

  10. #25
    orange's Avatar
    orange is online now Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,742
    writeprivate,

    If you want to pass your evolving database to me with some instructions of what you have and what you are trying to solve/resolve/design, I will look at it.
    Best to put it into a zip file.

  11. #26
    writeprivate is offline Advanced Access Coder
    Windows 10 Access 2021
    Join Date
    Feb 2023
    Posts
    42
    Very kind - thanks, i will do that. I am just fixing a bug that has come up as I have been tweaking and i want to repair before I send to you.

  12. #27
    writeprivate is offline Advanced Access Coder
    Windows 10 Access 2021
    Join Date
    Feb 2023
    Posts
    42
    Hi Orange, I have sent you a PM with a link to the db - thanks

  13. #28
    orange's Avatar
    orange is online now Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,742
    Looking at your database.
    Had issues with form filling and purchased Msoft for 1000 not 100 --my fat finger mistake.
    Stepped through the button click routine and finally got the BatchAllocation report to work with unit sale.

    For longest time I could not get a value in Purchase (purchase_running_total)??

    I added a new Module1 and renamed the previous as _Orig where I prefixed procedures with "X", since they would be seen as duplicates/ambiguous

    Click image for larger version. 

Name:	BatchAllocation_TobySingleUnit.png 
Views:	32 
Size:	27.9 KB 
ID:	49726

    Click image for larger version. 

Name:	CheckAvailabilityadded.png 
Views:	32 
Size:	28.6 KB 
ID:	49727

  14. #29
    orange's Avatar
    orange is online now Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,742
    For writeprivate

    Click image for larger version. 

Name:	StockValuationUnitSalesMSoft.png 
Views:	32 
Size:	22.5 KB 
ID:	49728

    Click image for larger version. 

Name:	QryStockAvailableWithAndWithoutSales_Rev.png 
Views:	31 
Size:	72.6 KB 
ID:	49729

    If you run the query by itself, you should see this result(based on my Purchase and sales)

    batch_number purchase_date product_name Purchased Qty purchase_price AvailableQty StockValue
    1 15-Feb-23 Microsoft 3 1000 2 2000

    Good luck.

  15. #30
    writeprivate is offline Advanced Access Coder
    Windows 10 Access 2021
    Join Date
    Feb 2023
    Posts
    42
    AMAZING - it works beautifully - that missing "=" was the issue. Thank you so much

Page 2 of 3 FirstFirst 123 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. FIFO For Shares Stock - Access 2010
    By bhavik1978 in forum Programming
    Replies: 1
    Last Post: 04-11-2020, 04:15 PM
  2. Replies: 0
    Last Post: 08-29-2017, 02:49 AM
  3. Replies: 8
    Last Post: 07-03-2015, 05:03 PM
  4. Replies: 2
    Last Post: 07-23-2011, 08:16 PM
  5. Date not Sorting Correctly (screenshot attached)
    By KrenzyRyan in forum Queries
    Replies: 5
    Last Post: 06-27-2011, 01:44 PM

Tags for this Thread

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