Results 1 to 10 of 10
  1. #1
    JakeMann41 is offline Novice
    Windows 11 Office 365
    Join Date
    Aug 2024
    Posts
    14

    Append Query


    Hi Guys

    I've written an append query that updates a table from another table based on what item I want.

    However when i run it it is duplicating the number of entries on the new table. What have I done to cause that?
    Attached Thumbnails Attached Thumbnails duplicate fields.png   append query.png  

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,570
    That is what an Append query does?, append new records to a table?

    Perhaps you want an Update query once a record has been added to that table.?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    ano is offline Competent Performer
    Windows 11 Office 365
    Join Date
    Nov 2023
    Posts
    204
    1st) stock is summation from buy/sell not a field in the database
    2nd) transaction date belongs to buy/sell not to item
    3rd) without criteria all items are processed

  4. #4
    Join Date
    Apr 2017
    Posts
    1,793
    A normal way to keep the stock of items in database is:
    tblItems: ItemId, ItemName, ItemType,ItemUnit ... (contains a general and permanent info about every item);
    tblItemTransactions: TransactionID, TransactionDate, StorageID, TransactionTypeID, TransactionAmount... (Contains the info about movements of items in certain location/storage. In case all movements are in same storage, StorageID can be dropped. TransactionTypeID determines, what kind of transaction the current one was, and was it incoming or outgoing one.);
    tblTransactionTypes: TransactionTypeID, TransactionType, TransactionDirection (TransactionDirection will be 1 for incoming transactions, and -1 for outgoing transactions).

    The stock of any item at any date can be calculated whenever it is needed as sum of (ItemAmount*TransactionDirection) from all transactions earlier or equal of query date. There is no need to save it anywhere (and doing so may be a source of problems for you).

    In case the cumber of transactions is big, you may need to have e.g. yearly inventories, like
    tblItemInventory: InventoryID, InventoryDate, ItemID, InventoryAmount
    Then stock of any item at any date can be calculated whenever it is needed as InventoryAmount + sum of (ItemAmount*TransactionDirection) from all transactions later as inventory date, and earlier or equal of query date.

  5. #5
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,180
    In every well designed stock database you do need a stock table, every logistic engineer will tell you this and every logistics application I encountered works this way. Calculating the + and - never does the job as it should, I don't know why only in Access this should be different.

  6. #6
    ano is offline Competent Performer
    Windows 11 Office 365
    Join Date
    Nov 2023
    Posts
    204
    @noellag
    every database should not save (re)calculated fields thats not database minded , what u see in forms does not need to be the same as the tables.
    the example of extra field +/- is also not the efficient way <zero is out >zero is in (sell/buy) to check in form calculate the stock before change (get_focus) and after change (after_update) calculate again and display "buy"/"sell" depending on result diff old/new stock so the one see confirmd its action.
    more important the table should not allow update only insert . if interesting a field with broken/stolen/misplaced .

  7. #7
    ano is offline Competent Performer
    Windows 11 Office 365
    Join Date
    Nov 2023
    Posts
    204
    why u have 2 tables with field currentstock? Items is only basic item info without history , history belong in separated table with date.
    startingstock is always zero so useless
    currentstock is sum(currentstock) from currentstock table and that miss the date. yes "out" is negative, "in" is positive
    and item in currentstock should match id from item table

  8. #8
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,180
    @ano
    the stock table is the heart of your application, you don't want it to be calculated on each access and from my engineering degree + 30 years of experience: starting stock is not always zero.
    Table design is important but should take into account reality.
    Avril's post is a very good start. But you always need a stock table: you need to know very fast if you have enough stock for orders, if you have enough room to stow away new input, if you need to order new items, create picking lists, ect ...
    In most cases you have the movement tables + queue tables. This means orders come in through email or IDE and you haven't checked yet if you have enough stock, look upon it as reservations.
    If you have to calculate the stock each time for every action you can run into trouble very fast.
    If after every movement the stock is set up to date through an update query (VBA or macro result in the same on the database layer) you're good.

  9. #9
    ano is offline Competent Performer
    Windows 11 Office 365
    Join Date
    Nov 2023
    Posts
    204
    your reason is fake your database design will fail and fail again and again and you have no history to adjust your picking list.
    it is extra bad design because u have 2 same field in your database and more over you connect on text item

  10. #10
    ano is offline Competent Performer
    Windows 11 Office 365
    Join Date
    Nov 2023
    Posts
    204
    some optimizing points.


    if currentstock is getting very large , so sum becum slow, then add a broken with the stock , add 1 to the field that keep track of the recent stock and add misplaced with the stock , so you only sum the recent stock (highest)this is during the new order procedure.


    currentstock : id(autonumber),item(number),date(today),recent(num ber),(-)stock(number),reason(number)
    item : id(autonumber),item (text)
    minmax : id(autonumber) ,item(number) ,kind (number), stock (number)
    kind : id(autonumber), location(number),kind (text) {min (need order),max (max-stock to order)}
    location : id (autonumber) , location(text) {shelf,warehouse}
    reason: id(autonumber),reason(text) {misplaced,broken,lost,bought,sold}


    select item.item,sum(stock) from item,currentstock where item.id=currentstock.item and currentstock.recent=(select max(recent) from currentstock)

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

Similar Threads

  1. Replies: 4
    Last Post: 02-03-2021, 08:32 AM
  2. Replies: 19
    Last Post: 10-03-2017, 09:10 AM
  3. Access can't append all the records in the append query
    By fluffyvampirekitten in forum Access
    Replies: 2
    Last Post: 08-27-2015, 01:53 AM
  4. Replies: 1
    Last Post: 10-06-2011, 08:37 AM
  5. Replies: 7
    Last Post: 07-21-2011, 01:01 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