slammedtgs
New member
- Local time
- Today, 11:07
- Joined
- Feb 16, 2013
- Messages
- 4
Help with nested Do Loop(s) - Solved
Hello Everyone,
I am working on improving a database that I inherited which has several routine update queries based on various criteria. I am working on automating this process and I have a working solution (band-aid). My current solution uses pages of code in place of a loop to run the update queries based on static criteria. I am looking to make this process more dynamic.
I've created two tables that list my criteria for each loop: Service Line and Financial Class.
My current code works until I get to the last service line and the last financial class and then I get a debug error, Run time 3021 - No Current Record. The error is on the active MsgBox() line. I have been successful in running an excel version of this code with nested foreach loops.
I think I just need to have something to trigger an Exit Do; I have tried an if rstFinancialClass.eof = true then exit do. That idea didnt work
Any pointers would be appreciated. Thanks.
Hello Everyone,
I am working on improving a database that I inherited which has several routine update queries based on various criteria. I am working on automating this process and I have a working solution (band-aid). My current solution uses pages of code in place of a loop to run the update queries based on static criteria. I am looking to make this process more dynamic.
I've created two tables that list my criteria for each loop: Service Line and Financial Class.
My current code works until I get to the last service line and the last financial class and then I get a debug error, Run time 3021 - No Current Record. The error is on the active MsgBox() line. I have been successful in running an excel version of this code with nested foreach loops.
I think I just need to have something to trigger an Exit Do; I have tried an if rstFinancialClass.eof = true then exit do. That idea didnt work
Any pointers would be appreciated. Thanks.
Code:
Sub Concept()
Dim rstServiceLine As dao.Recordset
Dim SServierLine As String
Dim rstFinancialClass As dao.Recordset
Dim FFinancialClass As String
Set rstServiceLine = CurrentDb.OpenRecordset("Service_Lines", dbOpenDynaset) ' Set variable to database table Service_Lines (listing of all service lines to update
rstServiceLine.MoveLast
rstServiceLine.MoveFirst ' Select first record to set variable
' begin Service line
Do While Not rstServiceLine.EOF
'''MsgBox ("Service Line: " & rstServiceLine!Service_Line_Grouper)
rstServiceLine.MoveNext
' Begin Financial Class Code here
Set rstFinancialClass = CurrentDb.OpenRecordset("Financial_Classes", dbOpenDynaset)
rstFinancialClass.MoveLast
'rstFinancialClass.MoveFirst
Do While Not rstFinancialClass.EOF
MsgBox ("Service Line: " & rstServiceLine!Service_Line_Grouper & " Financial Class: " & rstFinancialClass!Financial_Class)
rstFinancialClass.MoveNext
Loop
rstFinancialClass.Close
Set rstFinancialClass = Nothing
' End Financial Class Code Here
Loop
rstServiceLine.Close ' Close service line recordset
Set rstServiceLine = Nothing
End Sub
Last edited: