Results 1 to 12 of 12
  1. #1
    namu23 is offline Novice
    Windows 7 Access 2007
    Join Date
    Nov 2010
    Posts
    17

    Smile Calculating Stock On Hand

    Hi,

    I know this is a very common question but it seems that I am still lost and i think my database is little different from other designs. I was thinking that my tables are fine until i cannot move any further and i get stuck. I hope someone can help me build my query to calculate the stock on hand. Thank you.

    Click image for larger version. 

Name:	mydb.jpg 
Views:	28 
Size:	119.1 KB 
ID:	19136

    Here, i would like to show the relationship of the two tables.

    Click image for larger version. 

Name:	mydb rel.jpg 
Views:	28 
Size:	246.6 KB 
ID:	19137



    Should you have other suggestions or the best way to setup my tables and query, i would be very thankful.
    Last edited by namu23; 12-28-2014 at 09:18 AM. Reason: show table relation, attached picture

  2. #2
    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,722

  3. #3
    namu23 is offline Novice
    Windows 7 Access 2007
    Join Date
    Nov 2010
    Posts
    17
    Hi Orange,

    Thanks for sending the reference. Sorry but I forgot to say that I do not know how to code in vba and SQL. I just need to build the correct Query to calculate the stock on hand. Hope you can help me. Thank you.

  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,722
    From the link I gave you:

    "How do I update the Quantity On Hand each time an item is sold/used?" The simple answer is: You don't! You calculate the value when you need it.

    The calculation is very simple: the total number acquired, less the number disposed of. Just use DSum() on the table of acquisitions to get the number acquired for any product. Another DSum() expression on the table of uses/invoices gets the number disposed of."

    What have you tried? What result?

  5. #5
    namu23 is offline Novice
    Windows 7 Access 2007
    Join Date
    Nov 2010
    Posts
    17
    Hi Orange,

    Yup, that is what i want to achieve because i don't want to update the quantity on hand nor store them somewhere. I just want to calculate the stock on hand every time i run the query. I did not try the Dsum though because i dont know how to do it.

    Kindly check my screenshot below for the query i have tried.

    Click image for larger version. 

Name:	query.png 
Views:	27 
Size:	42.7 KB 
ID:	19143

    The result is this which is not correct.

    Click image for larger version. 

Name:	result.png 
Views:	27 
Size:	24.7 KB 
ID:	19144

    as you will notice on my first post, the sum of quantity received for PODETAILS_ID 8 has to be 250 only.
    Last edited by namu23; 12-28-2014 at 10:48 AM. Reason: change screenshot resolution

  6. #6
    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,722
    Please post a copy of your database.

  7. #7
    namu23 is offline Novice
    Windows 7 Access 2007
    Join Date
    Nov 2010
    Posts
    17
    Kindly check the attachment please.

    Thank you.

    MyDB.zip

  8. #8
    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,722
    I could not follow your relationships diagram. For your own benefit you should put in descriptions for your tables and fields. It would be less confusing.
    I rearranged your query as
    Code:
    SELECT tb_Receiving.PODetails_ID, Sum(Nz([tb_Receiving].[QuantityReceived],0)) AS QtyReceived
    , Sum(Nz([tb_issuances].[QuantityIssue],0)) AS QtyIssued
    , Sum(Nz([QuantityReceived],0)-Nz([QuantityIssue],0)) AS [Stock on Hand]
    FROM tb_Receiving LEFT JOIN tb_Issuances ON
     tb_Receiving.QuantityReceived = tb_Issuances.QuantityIssue
    GROUP BY tb_Receiving.PODetails_ID;
    And got this result

    PODetails_ID QtyReceived QtyIssued Stock on Hand
    8 250 100 150
    9 250 25 225
    10 150 100 50
    11 250 30 220
    12 100 100 0

    Are you only receiving and issuing 1 Product/Item??
    Last edited by orange; 12-28-2014 at 02:19 PM. Reason: Spelling

  9. #9
    namu23 is offline Novice
    Windows 7 Access 2007
    Join Date
    Nov 2010
    Posts
    17
    Hi Orange,

    Sorry for my late reply. I copy paste the SQL but when i run the query, it is not calculating and i'm getting the same result every time.

    The relation between the tb_Receiving and tb_Issuance is they are connected through tb_Receiving.ID and tb_Issuances.Receiving_ID.

    My explanation is as follow:

    > As you noticed the screenshot in my first post, there are two 8 on the tb_Receiving.PODetails_ID. It means first delivery is not complete so i received the item for the 2nd time on different date.
    > Also, in my first post, there are two 2 tb_Issuance.Receiving_ID because i issue the item on 2 different dates.

    And yes, i am only receiving and issuing 1 item at a time but with different quantity.

    Thank you.

  10. #10
    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,722
    As I said earlier I can not understand your relationship diagram.
    When you post, you usually describe the issue, your environment and your expertise/familiarity with database and Access.
    You posted some images with minimal description.

    In post 5 you said the 350 quantity was an error --- that was a flag to me saying there was something wrong with your query. It's your data and your query, so if you can't make sense of it, how can someone unfamiliar with your issue and your environment.

    I see in your receiving table that you have 2 receipts of PODetailsID = 8, but I also see no mention of Product or Item, so I don't know what you are receiving. However, I do see the total of PODetailsID = 8 received as 250.

    I tried playing with your numbers to make some sense of the data. I passed on a best guess.

    This sort of comment
    It means first delivery is not complete so i received the item for the 2nd time on different date.
    No body would guess that -- you received quantities of something of different dates. If you get a partial delivery, you should have a means to identify partial delivery.
    Same thing with Invoices and Payments if that's part of your business.
    However, if you want to describe your receiving and issuance tables in plain English, and exactly WHAT you are trying to do, I'll take a look.

    But a few images and no details and no descriptions in plain English will not get the readers to respond.

    Is every receipt and issuance for the same thing/item?

  11. #11
    namu23 is offline Novice
    Windows 7 Access 2007
    Join Date
    Nov 2010
    Posts
    17
    Hi Orange,

    Thank you for highlighting me about the "means to identify the partial delivery and that you cannot see the Product Item" (I was thinking like, yeah how can you calculate something if you don't know the products you want to calculate?) In that case, i modified the table relationship of tb_Receiving and tb_Issuances. What i did is i connected them to the tb_PurchaseOrderDetails.ID.

    Click image for larger version. 

Name:	tbrelationship.png 
Views:	21 
Size:	131.9 KB 
ID:	19153

    and then i made a separate query for the receiving, issuance, stock

    Click image for larger version. 

Name:	qryRelation.png 
Views:	21 
Size:	86.1 KB 
ID:	19154

    and viola! i think i just solved my problem

    Click image for larger version. 

Name:	qryResultOK.png 
Views:	22 
Size:	71.8 KB 
ID:	19155


    Thanks a lot. I really appreciate your help!

  12. #12
    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,722
    Glad you have it sorted out. Good luck with your project.

    Remember, readers only know what you tell them, so treat us like people in a line at McDonalds --
    pretend we don't know you, nor Access , nor database. If we said "What's the big issue today?" -- tell us
    in simple plain English the old what, why, where, when, how and how much from the 30000 foot overview.

    You may find links here of value.

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

Similar Threads

  1. Still can't get quantiy on hand for all records
    By nightangel73 in forum Queries
    Replies: 6
    Last Post: 06-10-2014, 05:21 AM
  2. Calculating stock balance
    By Demerit in forum Queries
    Replies: 11
    Last Post: 12-17-2013, 01:57 AM
  3. Replies: 9
    Last Post: 10-21-2013, 02:10 PM
  4. calculating On Hand Quantity
    By hbm001 in forum Queries
    Replies: 18
    Last Post: 04-24-2012, 09:42 AM
  5. Calculating Current Stock in Inventory/Warehouse
    By yohansetiawan in forum Access
    Replies: 5
    Last Post: 03-14-2012, 09:05 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