Results 1 to 4 of 4
  1. #1
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839

    Looping through table 1 to update table 2

    I am trying to update a table from another table where:



    If Table1.networks = Table2.Networks then
    Update Table1.Networks with Table2.Net

    I am having difficulties with having table1.networks being compared to Table2

    My intent is to have table2 loop through its contents to see if any rows are equal. if not then it goes to The next row in table1.networks


    Code:
    Private Sub funcky_Click()
    Dim rU As DAO.Recordset, rU2 As DAO.Recordset
    Dim Net As String
    
    Set rU = CurrentDb.OpenRecordset("Data")
    Set rU2 = CurrentDb.OpenRecordset("NetworkChange")
    
    If rU.BOF And rU.EOF Then
    
                    rU.Close
                Else
                    rU.MoveLast
                    rU.MoveFirst
                    rU2.MoveFirst
    
        Do While Not rU.EOF
            Do While Not rU2.EOF
    
    If rU![Networks] = rU2![Networks] Then
        Net = Not IsNull(rU2![Networks2])
    Elseif rU![Networks] = "" Then
        Net = ""
    Else:     Net = rU![Networks]
    End If
            
    
         Loop
             rU2.MoveNext        
            rU.Edit
            rU![Networks2] = Net
            rU.Update
            rU.MoveNext
    
        Loop
    End If
           rU.Close
           Set rU = Nothing
    End Sub
    
    Private Sub Test_Click()
    
    Dim rU As DAO.Recordset
    
    Set rU = CurrentDb.OpenRecordset("Data")
           
    If rU.BOF And rU.EOF Then
                    rU.Close
                Else
                    rU.MoveLast
                    rU.MoveFirst
    
        Do While Not rU.EOF
            rU.Edit
            rU![Networks2] = Null
            rU.Update
            rU.MoveNext
        Loop
    End If
    
           rU2.Close
           Set rU2 = Nothing
    
           rU.Close
           Set rU = Nothing
    End Sub

  2. #2
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Why not use an Update query?

  3. #3
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    839
    DUH!,
    Thanks, much quicker.

  4. #4
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Yeah, sometimes we get so involved in getting something to work!

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

Similar Threads

  1. Replies: 3
    Last Post: 08-08-2016, 07:28 AM
  2. ADODB looping through and update help!
    By fluffyvampirekitten in forum Access
    Replies: 5
    Last Post: 01-11-2016, 10:33 AM
  3. Looping through fields of a record (query or table)
    By PlamenGo in forum Programming
    Replies: 2
    Last Post: 04-02-2014, 05:44 AM
  4. Replies: 9
    Last Post: 01-31-2014, 12:09 PM
  5. Replies: 1
    Last Post: 02-08-2012, 04:50 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