Ok I'm having some problems with this code not doing what I'd like for it to do. I'd like for it to loop through all the records in the MAIN table with the outer loop and then loop and compare the MAIN table records to the ALTER table records adding records that are not in the ALTER table. In other words, if the record is in the ALTER table AND the MAIN table it should not appear in the listbox. This code only loops around 10 times. The MAIN table has over 45,000 records in it. Any suggestions anyone? Thanks.
VB Code:
  1. Set connection = New ADODB.connection
  2.     connection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  3.         "Data Source= C:\Documents and Settings\P6B0438\My Documents\Programs\Visual Basic\DB\cycleCount.mdb"
  4.     connection.Open
  5.    
  6.     Set newConnection = New ADODB.connection
  7.     newConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  8.         "Data Source= C:\Documents and Settings\P6B0438\My Documents\Programs\Visual Basic\DB\cycleCount.mdb"
  9.     newConnection.Open
  10.    
  11.     Set recordSet = New ADODB.recordSet
  12.     Set newRecordSet = New ADODB.recordSet
  13.      
  14.     Dim inAlterTable As Boolean
  15.     Dim selectStatement As String
  16.     Dim newSelectStatement As String
  17.    
  18.     inAlterTable = False
  19.     selectStatement = "SELECT DISTINCT PICKSL,DFP,PROD,DESC FROM MAIN"
  20.     'newSelectStatement = "SELECT DISTINCT PICKSL,DFP,DESC FROM [ALTER]"
  21.    
  22.     recordSet.Open selectStatement, connection, adOpenKeyset, adLockPessimistic, adCmdText
  23.     'newRecordSet.Open newSelectStatement, newConnection, adOpenKeyset, adLockPessimistic, adCmdText
  24.     newRecordSet.Open "[ALTER]", newConnection, adOpenKeyset, adLockPessimistic, adCmdTable
  25.    
  26.     recordSet.MoveFirst
  27.     newRecordSet.MoveFirst
  28.        
  29.     Do Until recordSet.EOF
  30.         Do Until newRecordSet.EOF
  31.             If (recordSet.Fields("PICKSL") = newRecordSet.Fields("PICKSL") And _
  32.                 recordSet.Fields("DFP") = newRecordSet.Fields("DFP") And _
  33.                 recordSet.Fields("PROD") = newRecordSet.Fields("PROD") And _
  34.                 recordSet.Fields("DESC") = newRecordSet.Fields("DESC")) Then
  35.                 inAlterTable = True
  36.             End If
  37.             DoEvents
  38.             newRecordSet.MoveNext
  39.         Loop
  40.         If (inAlterTable = False) Then
  41.             lstFirstScreen.AddItem (recordSet.Fields("PICKSL") & vbTab _
  42.                 & recordSet.Fields("DFP") & vbTab _
  43.                 & recordSet.Fields("PROD") & vbTab _
  44.                 & recordSet.Fields("Desc"))
  45.         End If
  46.         DoEvents
  47.         recordSet.MoveNext
  48.     Loop
  49.    
  50.     recordSet.Close
  51.     connection.Close
  52.     Set recordSet = Nothing
  53.     Set connection = Nothing