Wasn't sure......OK, try this:
Code:
Public Sub compareTables()
Dim D As DAO.Database
Dim S As DAO.Recordset
Dim L As DAO.Recordset
Dim sSQL As String
Dim MatchCount As Integer
Dim x As Integer
Dim y As Integer
Dim iMax As Integer
Dim iMin As Integer
Dim tmp As Integer
Dim Inner As Long
Dim Outer As Long
Dim L_tmp As Integer
Dim S_tmp As Integer
Set D = CurrentDb
iMin = 0 ' index of first field in recordsets
iMax = 5 ' index of last field in recordsets
sSQL = "SELECT Small.N01, Small.N02, Small.N03, Small.N04, Small.N05, Small.N06"
sSQL = sSQL & " FROM Small;"
Set S = D.OpenRecordset(sSQL)
sSQL = "SELECT Large.N01, Large.N02, Large.N03, Large.N04, Large.N05, Large.N06,"
sSQL = sSQL & " Large.Countfor1s, Large.Countfor2s, Large.Countfor3s, Large.Countfor4s, Large.Countfor5s, Large.Countfor6s"
sSQL = sSQL & " FROM Large;"
Set L = D.OpenRecordset(sSQL)
If (S.BOF And S.EOF) Or (L.BOF And L.EOF) Then
'one or the other tables has no records
S.Close
L.Close
Set S = Nothing
Set L = Nothing
Set D = Nothing
Exit Sub
End If
'populate recordsets
S.MoveLast
S.MoveFirst
L.MoveLast
Outer = 0
Inner = 0
'Loop thru the recordsets
Do Until S.EOF 'outer loop - this is by record
Outer = Outer + 1
L.MoveFirst
Do Until L.EOF 'inner loop - this is by record
Inner = Inner + 1
MatchCount = 0
For x = iMin To iMax 'S - this is by field
For y = iMin To iMax 'L - this is by field
'compare field values
S_tmp = S.Fields(x)
L_tmp = L.Fields(y)
If S.Fields(x) = L.Fields(y) Then
MatchCount = MatchCount + 1
End If
Next y
Next x
'-------------------
'this is where you would write the value of
' MatchCount to a table
If MatchCount > 0 Then
tmp = MatchCount
L.Edit
L.Fields("Countfor" & tmp & "s") = Nz(L.Fields("Countfor" & tmp & "s"), 0) + MatchCount
L.Update
End If
'-------------------
L.MoveNext
If Inner Mod 5 = 0 Then
' put some code here to update a couple of controls to show how
' many rows have been processed in both the outter (small) table
' and the inner (large) table.
' the variables "Outer" and "Inner" hold the numbers of records processed
'-******************
' Me.SomeControl = Outer
' Me.AnotherControl = Inner
' Me.Repaint
'-******************
End If
Loop
S.MoveNext
Loop
'clean up and exit
S.Close
L.Close
Set S = Nothing
Set L = Nothing
Set D = Nothing
MsgBox "Done "
End Sub
(Looks like something to do with the Lottery. If you win, do I get 10%
????? )