Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 26th, 2015, 04:21 PM
Registered User
 
Join Date: Jun 2015
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Recordset loop skipping entry

I have 2 identical tables of asset information. Table 1 has 251 records while table 2 has 84 records. All 84 records are in table 1 right now. My end goal is to be able to click a button, have vba script run, and table 2 updates table 1 with any changes from different fields. I know there are merging options with query and what not but the exact structure of my tables doesnt play well with it.

Right now, my code is able to loop through the values of each computername and display it. For some reason, when it gets to the 130th record of table one, the loop skips it and returns the 131st record, it stays one ahead for the rest of the loop and then prints the 130th record finally.

Since I am trying to compare field values, this sudden shift throws everything off. Any ideas why it skips?:confused:

Code:
Option Compare Database

Private Sub UpdateAssetsBTN_Click()
On Error GoTo Err_Proc

Dim rs1 As DAO.Recordset
Dim rs2 As DAO.Recordset

Set rs1 = CurrentDb.OpenRecordset("Assets1")
Set rs2 = CurrentDb.OpenRecordset("Assets2")

If rs1.RecordCount <> 0 And rs2.RecordCount <> 0 Then
    rs1.MoveFirst
    While Not rs1.EOF
        If rs1.Fields("ComputerName") Like "JT-*" Then
            Debug.Print "JT1: " + rs2.Fields("ComputerName")
            Debug.Print "IT1: " + rs1.Fields("ComputerName")
            rs2.MoveNext
        End If
        rs1.MoveNext
    Wend
End If

'always close what you open
Exit_Proc:
 On Error Resume Next
 rs.Close
 Set rs = Nothing
 Exit Sub
Err_Proc:
 MsgBox Err.Number & ": " & Err.Description
 Resume Exit_Proc

End Sub





Similar Threads
Thread Thread Starter Forum Replies Last Post
Array Loop skipping loop in VBA jeskit Access VBA 5 March 20th, 2012 10:03 AM
recordset not showing up on page loop pablohoney Classic ASP Databases 1 December 14th, 2005 06:43 PM
Querying Recordset with a Loop rabu Access VBA 10 December 14th, 2005 04:49 PM
Filter recordset in loop Freddyfred Access 1 February 15th, 2005 09:09 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.