Results 1 to 2 of 2
  1. #1
    Jack Zasadzinski is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Feb 2016
    Posts
    1

    Question Populating an inventory value in one record with data from the prior record

    I have an inventory ledger file of sales and inventory information by store that only adds a record if there is activity that day or week. I am trying to use this to do rollups of inventory levels. For example, I may have a record for an item in week 1 in store 1 with sales and inventory, but there was no activity in weeks 2 and 3 so the next record is in week 4. The inventory level did not change since there was no sales activity. If I sum all of the records for all stores by week, the inventory in weeks 2 and 3 would be understated because it did not have a record for that store for those weeks. I have created a table that created records for all of the missing weeks but I don't know an easy way to populate the inventory fields in the missing weeks. My current table looks like this.

    Week Store Beginning Inventory Sales Ending Inventory


    1 1 100 5 95
    2 1
    3 1
    4 1 95 10 85

    The beginning and ending inventories for 2 and 3 are 95 since there was no sales activity. I know how to do this in Excel but the file has 5 million records so it's not practical to move the data. Any help would be appreciated.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    Heres some code you could run to scan the records ,paste code into a module or form.
    if it sees a blank, it fills it in.
    Sort the records and save the query as : qsInventorySort

    Code:
    Public Sub FillGaps()
    Dim rst
    Dim vStore, vStart, vEnd
    Dim vStorePrev, vStartPrev, vEndPrev
    Const kBEGfld = "[Beginning Inventory]"
    Const kENDfld = "[Ending Inventory]"
    Set rst = CurrentDb.OpenRecordset("qsInventorySort")
    With rst
      While Not .EOF
          vStore = .Fields("Store").Value & ""
          vStart = .Fields(kBEGfld).Value & ""
          vEnd = .Fields(kENDfld).Value & ""
         
         If vStore = vStorePrev Then
            If vStart = "" Then
               .Fields(kBEGfld).Value = vStartPrev
               .Fields(kENDfld).Value = vStartPrev
            End If
         End If
         
         vStorePrev = vStore
         vStartPrev = vStart
         vEndPrev = vEnd
         .MoveNext
      Wend
    End With
    Set rst = Nothing
    End Sub

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

Similar Threads

  1. Replies: 1
    Last Post: 09-04-2013, 08:57 AM
  2. Add one day to prior record's date/ how??
    By mkfloque in forum Access
    Replies: 3
    Last Post: 05-30-2012, 04:44 AM
  3. Populating Null data with Next Available Record
    By Kimbertha in forum Queries
    Replies: 5
    Last Post: 10-07-2010, 07:54 PM
  4. Populating Null Data with Next Available Record
    By Kimbertha in forum Programming
    Replies: 6
    Last Post: 09-25-2010, 11:02 AM
  5. New record take on all values of prior?
    By cps6568 in forum Access
    Replies: 3
    Last Post: 01-12-2010, 04:14 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