What am doing wrong? I am trying to print all the categories in the recordset and all the products for the current category using VBA. Basically, I am trying to loop through the recordset until EOF. Within that loop I am trying to loop through products until change of category. I am getting “Run-time error ‘3021’” No current record error message. I tried various method to overcome the problem by using Do Until, Do While but all the methods I used crashed on the same error. Find attached Access2000 file sample and code below.
PS: I need to cyctle through 3 loops, the sample below and the attached file are just a practice (part of Nortwind sample) I used to play with because I could not get my database to work. It only shows two loops but I couldn’t even get it to work. What I need to do is the following:
Open Recordset
Loop Until rst.EOF
Save rst!LastDate
Loop Until Saved rst!LastDate changes OR recordset is finished (rst.EOF)
Save rst!PublicationType
Loop Until Saved rst!PublicationType changes OR Saved rst!LastDate changes OR recordset is finished (rst.EOF)
Do various tasks
End Loop
End Loop
End Loop
Close Recordset
How do I put this in code? Any help would be greatly appreciated. Thank you.
‘Sample I played with for two loops (didn’t work)
Private Sub cmdTesting_Click()
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim lngSavedCategory As Long
Dim lngSavedProduct As Long
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(“qryTesting”)
Do Until rst.EOF
lngSavedCategory = rst!CategoryID
Me!txtCategory = Me!txtCategory & vbCrLf & rst!CategoryID & “: ” & rst!CategoryName
Do Until rst.EOF And lngSavedCategory rst!CategoryID
Me!txtProduct = Me!txtProduct & vbCrLf & rst!ProductID & “: ” & rst!ProductName
rst.MoveNext
Loop
Me!txtProduct = Me!txtProduct & vbCrLf
Loop
End Sub