I am running excel 2003. I typically get this error if the spreadsheet has been created and for some reason no data is populating the spreadsheet. I was hoping to get help on how to trap the error, so I can still save the bad spreadsheet, so the code will continue and keep on processing. The highlighted code is causing the error. The variables rstRpts![tabnm], strNewWkbk and iRpt have legitimate values in them, so I don't know where to proceed. Any help is appreciated.
Tom
Tom
Code:
' Get list of reports for this print set
strSQL = "SELECT ord,tabnm,fname FROM PROC_TableOfContents ORDER BY ord;"
Set rstRpts = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot)
If Not rstRpts.EOF Then
With rstRpts
.MoveLast
.MoveFirst
End With
For iRpt = 1 To rstRpts.RecordCount ' Cycle through reports
goXL.Workbooks.Open Filename:=(strSrcPath) & (rstRpts![fname]) ' Open Report
' *** Get number of pages and update list
' Count Pages in Report
iPageCnt = ActiveSheet.HPageBreaks.Count + 1
' Update with Pages
strSQL = "UPDATE PROC_TableOfContents SET pgs = " & (iPageCnt) & " WHERE ord = " & (rstRpts![ord]) & ";"
CurrentDb.Execute strSQL
' Copy to print set and close
With goXL
[Blue] .Sheets("" & (rstRpts![tabnm]) & "").Copy After:=Workbooks(strNewWkbk).Worksheets((iRpt + 2)) [/Blue]
.Workbooks(2).Close SaveChanges:=False
End With
rstRpts.MoveNext
Next iRpt
End If
rstRpts.Close
Set rstRpts = Nothing