Search code examples
crystal-reportsvb6runtime

Why is this block of code producing runtime error 91


This block of code is causing runtime error 91 or with block not set error this code is for opening reports in crystal report in vb6

For DocCodeCount = 0 To cboDoctorsCode.ListCount - 1
    strReportTitle = "DOCTOR'S TRANSMITTAL COPY"
    strSqlStatement = "PFMS '" & cboControlCode.Text & "', '" & cboDoctorsCode.List(DocCodeCount) & "', '" & sCurrentUserName & "'"
    strFilename = App.Path & "\Reports\ClaimsBillProc\PF MS.rpt"
    newRpt.OpenReport vADOConnection, strSqlStatement, strFilename, strReportTitle, 3, False
    Set newRpt = Nothing
Next

When used in 1 time opening of report it runs fine but when it is used in this manner in the loop it causes error.


Solution

  • The answer is quite clear: You destroy your object within the loop.

    This line is the obvious reason for your one time wonder:

     Set newRpt = Nothing