Results 1 to 5 of 5
  1. #1
    dtreffery is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    2

    Parsing a record into multiple records by date range

    I'm a green horn when it comes to Access, so please bare with me.

    I have a record in a table (Table1) with the following:

    Item Start End
    A 2012 2030

    I have another table (Table2) with the following:

    Item Start
    A 2018


    A 2025

    What I would like to do is update/append Table1 so that it looks like the following:

    Item Start End
    A 2012 2017
    A 2018 2024
    A 2025 2030

    The order of the records in Table2 should be irrelevant in the solution.

    I've been really struggling on where to begin with this one . I look forward to any suggestions. Thanks!

    Edit: I forgot to mention that there are many Items (A,B,C,D,etc.) in both tables.
    Last edited by dtreffery; 09-01-2015 at 09:18 AM. Reason: Addition

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    I expect this will require VBA code that opens and manipulates recordset object and writes records to table.

    How many records in Table2 for each Item?
    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.

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Your data is really messed up, so , lets clean up tbl1,
    make 2 queries using table1
    append data from tbl1 into tbl2 using only ITEM, START
    then append data in tbl1 into tbl2 using only ITEM, END

    then run the code sent to parse out table2 into table3. (never overwrite the original)
    change the tables in my code to match yours.
    Code:
    Public Function CollectTime()
    Dim sSql As String
    Dim vItm, vItm1, vStart, vStart1, vEnd
    Dim rst 'As Recordset
    
    
    sSql = "select * from TABLE2"
    Set rst = CurrentDb.OpenRecordset(sSql)
    With rst
          vItm = .Fields("Item").Value & ""
          vStart = .Fields("Start").Value & ""
          vEnd = vStart - vStart1 - 1
            
          If vItm = vItm1 Then
                If vStart1 <> "" Then
                      'post emails to a table
                  sSql = "Insert into table3 ([Item],[Start],[End]) values ('" & vItm & "','" & vStart & "','" & vEnd & "')"
                  DoCmd.RunSQL sSql
                End If
          Else
             vStart1 = ""
          End If
          
          vStart1 = vStart
          vItm1 = vItm
       .MoveNext
    End With
    
    
    rst.Close
    Set rst = Nothing
    End Function

  4. #4
    dtreffery is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    2
    Thanks for the response ranman! I create TABLE2 using the append queries as instructed, but when I execute the function, it doesn't actually do anything (including errors). Do I have to create TABLE3 before the function attempts to Insert records?

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    Yes, establish table 3 first. Surprised there were no error messages.
    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.

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

Similar Threads

  1. Replies: 40
    Last Post: 06-24-2015, 12:08 PM
  2. Replies: 3
    Last Post: 02-01-2015, 08:05 PM
  3. Create records for date range
    By wnicole in forum Access
    Replies: 1
    Last Post: 10-03-2013, 09:02 AM
  4. Replies: 5
    Last Post: 07-05-2013, 11:16 AM
  5. Date Range Report with Multiple Date Fields
    By StevenCV in forum Reports
    Replies: 13
    Last Post: 02-29-2012, 08:29 AM

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