Greets all ... I have something weird going on. I've got a nested do-while loop (code posted below) - rs2 is the outside loop and rs1 is the inside.
The outcome is that the code should loop once through rs2 then loop through every record in rs1 checking a condition. If true, assign a field value from rs1 to rs2, if not true assign "unknown" to rs2. Once a complete pass is done in rs1, it iterates to the next rs2 record and goes back through the sequence. It's not rocket science, but here is the issue ...
It only makes one group assignment in rs2 (meanining it finds a true for about 10 records). It places "unknown" in the rest and I know that it should through manual verification.
The label caption updates and repaints are to check the looping structure. The looping numbers come out correct. I've set breaks in the code and the iDataID assignments are correct and the records in rs1 are iterating for the conditions, but for some reason I can't figure out why it is not finding a true in the other remaining records.
Ideas?
-dK
The outcome is that the code should loop once through rs2 then loop through every record in rs1 checking a condition. If true, assign a field value from rs1 to rs2, if not true assign "unknown" to rs2. Once a complete pass is done in rs1, it iterates to the next rs2 record and goes back through the sequence. It's not rocket science, but here is the issue ...
It only makes one group assignment in rs2 (meanining it finds a true for about 10 records). It places "unknown" in the rest and I know that it should through manual verification.
The label caption updates and repaints are to check the looping structure. The looping numbers come out correct. I've set breaks in the code and the iDataID assignments are correct and the records in rs1 are iterating for the conditions, but for some reason I can't figure out why it is not finding a true in the other remaining records.
Ideas?
-dK
Code:
Dim dbs As DAO.Database
Dim rs1 As DAO.Recordset
Dim rs2 As DAO.Recordset
Dim iDataID As Long
Dim iCounter As Long
Dim jCounter As Long
iCounter = 0
jCounter = 0
Set dbs = CurrentDb
Set rs1 = dbs.OpenRecordset("Table1", dbOpenTable)
Set rs2 = dbs.OpenRecordset("Table2", dbOpenTable)
rs2.MoveFirst
Do While Not rs2.EOF
iDataID = rs2.Fields(4).Value
rs1.MoveFirst
Do While Not rs1.EOF
rs2.Edit
If iDataID >= rs1.Fields(2).Value And iDataID <= rs1.Fields(3).Value Then
rs2.Fields(1).Value = rs1.Fields(1).Value
Else
rs2.Fields(1).Value = "Unknown"
End If
rs2.Update
jCounter = jCounter + 1
Me.lblLabel1.Caption = "Total of " & jCounter & " inner loops executed."
Me.Repaint
rs1.MoveNext
Loop
iCounter = iCounter + 1
Me.lblLabel2.Caption = "Total of " & iCounter & " outer loops executed."
Me.Repaint
rs2.MoveNext
Loop
MsgBox "Job complete.
rs1.Close
rs2.Close
Set rs1 = Nothing
Set rs2 = Nothing
Set dbs = Nothing