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:
Set connection = New ADODB.connection connection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source= C:\Documents and Settings\P6B0438\My Documents\Programs\Visual Basic\DB\cycleCount.mdb" connection.Open Set newConnection = New ADODB.connection newConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source= C:\Documents and Settings\P6B0438\My Documents\Programs\Visual Basic\DB\cycleCount.mdb" newConnection.Open Set recordSet = New ADODB.recordSet Set newRecordSet = New ADODB.recordSet Dim inAlterTable As Boolean Dim selectStatement As String Dim newSelectStatement As String inAlterTable = False selectStatement = "SELECT DISTINCT PICKSL,DFP,PROD,DESC FROM MAIN" 'newSelectStatement = "SELECT DISTINCT PICKSL,DFP,DESC FROM [ALTER]" recordSet.Open selectStatement, connection, adOpenKeyset, adLockPessimistic, adCmdText 'newRecordSet.Open newSelectStatement, newConnection, adOpenKeyset, adLockPessimistic, adCmdText newRecordSet.Open "[ALTER]", newConnection, adOpenKeyset, adLockPessimistic, adCmdTable recordSet.MoveFirst newRecordSet.MoveFirst Do Until recordSet.EOF Do Until newRecordSet.EOF If (recordSet.Fields("PICKSL") = newRecordSet.Fields("PICKSL") And _ recordSet.Fields("DFP") = newRecordSet.Fields("DFP") And _ recordSet.Fields("PROD") = newRecordSet.Fields("PROD") And _ recordSet.Fields("DESC") = newRecordSet.Fields("DESC")) Then inAlterTable = True End If DoEvents newRecordSet.MoveNext Loop If (inAlterTable = False) Then lstFirstScreen.AddItem (recordSet.Fields("PICKSL") & vbTab _ & recordSet.Fields("DFP") & vbTab _ & recordSet.Fields("PROD") & vbTab _ & recordSet.Fields("Desc")) End If DoEvents recordSet.MoveNext Loop recordSet.Close connection.Close Set recordSet = Nothing Set connection = Nothing




Reply With Quote