我有这段代码,我试图过滤和比较表中的数据,内部循环运行正确的次数,但外部只运行一次,我不知道为什么。
Do While Not rstA.EOF
' Gets the first serial for filtering
rstA.MoveFirst
serialNumber = rstB!serial
rstB.Filter = "serial = '" & serialNumber & "'"
' A nested loop for the filtered rst and goes til the end of that
Do While Not rstB.EOF
If rstA.Fields("serial") = rstB.Fields("serial") Then
If rstA.Fields("accountnumber") <> rstB.Fields("accountnumber") Then
'Print Message
ElseIf rstA.Fields("model_number") <> rstB.Fields("model_number") Then
'Print Message
End If
Else
' This will always be the default until there are two matching serial numbers
' This will advnace rstA +1 and make rstFiltered stay put
' I had to work around the advancements on the outside of this statement
' Thats why I move rstA (+1 = 1) and rstFiltered (-1 +1 = 0)
'Print message
rstB.MovePrevious
End If
rstB.MoveNext
rstA.MoveNext
Loop
Loop
我试图在两个结束循环语句之间推进 rstB,例如:
rstB.MoveNext
但是编译器说记录集是空的。
编辑最终代码:
Do Until rstB.EOF
Do Until rstA.EOF
If rstA.Fields("serial") = rstB.Fields("serial") Then
If rstA.Fields("accountnumber") <> rstB.Fields("accountnumber") Then
accountMessage = "Account number A, " & rstA.Fields("accountnumber") & ", and Account " _
& "number B, " & rstB.Fields("accountnumber") & ", for serial number ," & rstB.Fields("serial") & ", do not match."
Debug.Print accountMessage
ElseIf rstA.Fields("model_number") <> rstB.Fields("model_number") Then
accountMessage = "Model number A, " & rstA.Fields("model_number") & ", and Model " _
& "number B, " & rstB.Fields("model_number") & ", for serial number ," & rstB.Fields("serial") & ", do not match."
Debug.Print accountMessage
End If
Else
' This will always be the default until there are two matching serial numbers
' This will advnace rstA +1 and make rstFiltered stay put
' I had to work around the advancements on the outside of this statement
' Thats why I move rstA (+1 = 1) and rstFiltered (-1 +1 = 0)
rstB.MoveNext
rstA.MovePrevious
End If
rstA.MoveNext
Loop
rstB.MoveNext
Loop