I'm a little confused myself, but I'll at least post some code that I created which will cover the first 2 conditions:
The code will cross reference 'every' Record in Table1 (rs1) against 'every' Record in the Standard Values Table (Table2 - rs2). The Fields [Field1], [Field2], [Field3], and [Field4] exist in both Tables, are NUMERIC (LONG INTEGER), and are synchronized. The code will record 2 unique circumstances that you had previously indicated, and are referenced by items 1 and 2 above. The Absolute Record Position for both Recordsets will also be contained in the Output. The Output can easily be redirected to a Table, Text File, Excel Worksheets, etc. The code is easily expandable to include additional functionality.
You must keep in mind 2 important points:
Sample OUTPUT:
- An exact Match on all 4 Fields
- Exact Match on Fields 3 and 4 only, no Match on Fields 1 and 2
The code will cross reference 'every' Record in Table1 (rs1) against 'every' Record in the Standard Values Table (Table2 - rs2). The Fields [Field1], [Field2], [Field3], and [Field4] exist in both Tables, are NUMERIC (LONG INTEGER), and are synchronized. The code will record 2 unique circumstances that you had previously indicated, and are referenced by items 1 and 2 above. The Absolute Record Position for both Recordsets will also be contained in the Output. The Output can easily be redirected to a Table, Text File, Excel Worksheets, etc. The code is easily expandable to include additional functionality.
You must keep in mind 2 important points:
- Processing of 18,000 Records involves 324,000,000 iterations of the Nested Loops.
- The Output will only be valid as long as the 'State' of both Tables remains constant, namely: no Additions, Deletions, Edits, etc.
Code:
Dim MyDB As DAO.Database Dim rs1 As DAO.Recordset Dim rs2 As DAO.Recordset Dim lngRS1 As Long Dim lngRS2 As Long lngRS1 = 0 lngRS2 = 0 Set MyDB = CurrentDb() Set rs1 = MyDB.OpenRecordset("Table1", dbOpenSnapshot, dbOpenForwardOnly) Set rs2 = MyDB.OpenRecordset("Table2", dbOpenSnapshot) Do While Not rs1.EOF lngRS1 = lngRS1 + 1 Do While Not rs2.EOF lngRS2 = lngRS2 + 1 If (rs1![Field1] = rs2![Field1]) And (rs1![Field2] = rs2![Field2]) And _ (rs1![Field3] = rs2![Field3]) And (rs1![Field4] = rs2![Field4]) Then Debug.Print "**Match on all 4 Fields: rs1(Record " & lngRS1 & ") <==> rs2(Record " & lngRS2 & ")" ElseIf (rs1![Field1] <> rs2![Field1]) And (rs1![Field2] <> rs2![Field2]) _ And (rs1![Field3] = rs2![Field3]) And (rs1![Field4] = rs2![Field4]) Then Debug.Print " |- *Field3 and Field4 Match: rs1(Record " & lngRS1 & ") <==> rs2(Record " & lngRS2 & ")" 'Else unsure of OP's intention 'Debug.Print "Mismatch: rs1(Record " & lngRS1 & ") <> rs2(Record " & lngRS2 & ")" End If rs2.MoveNext Loop rs2.MoveFirst rs1.MoveNext lngRS2 = 0 Loop rs1.Close rs2.Close Set rs1 = Nothing Set rs2 = Nothing
Code:
|- *Field3 and Field4 Match: rs1(Record 1) <==> rs2(Record 1) **Match on all 4 Fields: rs1(Record 1) <==> rs2(Record 8) |- *Field3 and Field4 Match: rs1(Record 3) <==> rs2(Record 7) |- *Field3 and Field4 Match: rs1(Record 6) <==> rs2(Record 4) **Match on all 4 Fields: rs1(Record 7) <==> rs2(Record 5) **Match on all 4 Fields: rs1(Record 7) <==> rs2(Record 6)
Comment