Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access 2003 runtime error 3021 no current record 1

Status
Not open for further replies.

vba317

Programmer
Mar 5, 2009
708
US
I have been struggling with a loop within a loop issue that I can't resolve. What I am trying to do is create a tab in an excel spreadsheet that has one providers summary information in it instead of everyone's. On my first loop I have no issue. It is the second loop that I get the error 3021. I would appreciate any help.
Tom

Code:
Do
        sProv1 = ""
        sSQLP = "SELECT p.provname ,p.Last " & _
                "FROM DICT_Prov p " & _
                "WHERE p.clntid = 41 AND p.provid > 2 " & _
                "ORDER BY p.provname;"
        Set rstP = CurrentDb.OpenRecordset(sSQLP, dbOpenSnapshot)
        If Not rstP.EOF Then
            With rstP
                .MoveLast
                .MoveFirst
            End With
            sLast = (rstP![Last])
            sProv = (rstP![provname])
        End If
        For P = 1 To rstP.RecordCount

            iRw = 6
            sSQL = "TRANSFORM Sum(DATA.rvu) AS SumOfrvu " & _
                   "SELECT Prov.provname " & _
                   "FROM (((DATA_ProvLessAssists DATA " & _
                   "INNER JOIN z_ProcessPds Pds ON DATA.clntid=Pds.clntid AND DATA.rptpd=Pds.rptpd) " & _
                   "INNER JOIN DICT_Prov Prov ON DATA.provid=Prov.provid) " & _
                   "INNER JOIN DICT_Dpt Dpt ON DATA.dptid=Dpt.dptid) " & _
                   "WHERE Pds.yrdiff=0 and Prov.provname='" & sProv & "'" & _
                 " GROUP BY Dpt.dptdesc, Prov.provname, Prov.Last " & _
                   "ORDER BY Dpt.dptdesc, Prov.provname, Pds.monasdt " & _
                   "PIVOT Pds.monasdt;"
            Set rstLA = CurrentDb.OpenRecordset(sSQL, dbOpenSnapshot)
            If Not rstLA.EOF Then
                With rstLA
                    .MoveLast
                    .MoveFirst
                End With
                X = 4
                For I = 1 To rstLA.RecordCount
                    With goXl.ActiveSheet
                        If sProv1 <> (rstP![provname]) Then X = X + 1
                        If sProv1 <> (rstP![provname]) Then sSheet = "RVU_LessAssists_" & X
                        If sProv1 <> (rstLA![provname]) Then goXl.Sheets(sSheet).Select
                        If sProv1 <> (rstLA![provname]) Then sSheet = "RVU_LessAssists_" & (rstLA![Last])
                        If sProv1 <> (rstLA![provname]) Then goXl.ActiveSheet.Name = sSheet
                        If sProv1 <> (rstP![provname]) Then goXl.Sheets(sSheet).Select
                        If sProv1 <> (rstP![provname]) Then goXl.Sheets(sSheet).Activate
                        If sProv1 <> (rstP![provname]) Then iRw = 6
                                                                  
                        goXl.Sheets(sSheet).Range("A6").CopyFromRecordset rstLA
                        
                        sProv1 = (rstP![provname])
                        rstLA.MoveNext
                    End With
                Next I

            End If    'If Not rstLA.EOF Then
            rstP.MoveNext
        Next P
    Loop Until rstLA.EOF
 
goXl.Sheets(sSheet).Range("A6").CopyFromRecordset rstLA
The above instruction put rstLA in an EOF condition, so you can't call rstLA.MoveNext after.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV I had to make some other changes to the code but it is working now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top