Reset Crystal Report from VB6.0

I am using crystal report OCX control 4.6 in a VB 6.0 program.  3 different reports are used to generate different output for a set of data.  1 form gets formulas and values sent into it from VB using crystalreport1.formulas(1)="string".  The problem occurs when I run the report with many formulas and then try to run another report with only a few formulas.  Crystal does not "reset" between "runs" and gives me a "Crystal Report Error # 20510 Invalid Formula name".  Is there a crystalreport1.reset or set crystalreport1=null command that will clear the crystalreport formula data??
jbettsAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
DRRYAN3Connect With a Mentor Commented:
I re-read your statement of the problem.  What happens if you run the three reports in succession beginning with the one with the fewest formulas and ending with the one with the most formulas?  Do you get the error?

If you do, then the OCX control instance is retaining the settings and you should either clear all possible formulas with a formulas(x) = "" before running, or put the viewer control on its own form which is created and destroyed for each new report.

I don't own version 4.6 but this behavior is not present in version 7 and beyond.
0
 
DRRYAN3Commented:
Almost sounds as if you are not destroying the reference to the control or closing it between reports.  Can you post the code section where you are printing the report?
0
 
jbettsAuthor Commented:
Private Sub cmd_printlst_Click()

Dim iresult1 As Integer

On Error GoTo errorhandle
   
    MousePointer = 11
    With CrystalReport1
        .WindowState = crptMaximized
        .ReportFileName = defaultpicfiles & "\itemreport.rpt"
        .DataFiles(0) = sdir & "\estimate.mdb"
        .Formulas(0) = "sdir='" & lbl_snum & "'"
        .Formulas(1) = "user='" & lbl_user & "'"
        iresult1 = .PrintReport
    If iresult1 <> 0 Then
        MsgBox "Crystal Report Error Number:" & .LastErrorNumber & .LastErrorString, vbOKOnly + vbExclamation, "Crystal Error"
    End If
    End With
    MousePointer = 0
Exit Sub

errorhandle:
    MsgBox "Some other error " & Err.Number & Err.Description, vbOKOnly + vbExclamation, "Print Error"
End Sub
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
DRRYAN3Commented:
I'm not that familiar with version 4.6.  You might add the line

.DiscardSavedData

after your .ReportFileName line.  The current versions do support a reset method.
0
 
jbettsAuthor Commented:
Tried the discardsaveddata ---- didn't work.  Tried that line a few places in code.  No go.
0
 
DRRYAN3Commented:
Are you calling this from a form with a button click?  How are you displaying the form?  Is your CrystalReport1 object dropped on the form with the button?

Put a break point on the statement MousePointer=11 and step through your code, examining the CrystalReport1 object in memory with the locals window.  Make sure that you have only one instance of the CrystalReport1 object loaded and have not made the mistake of referencing the object on the form instead of the object on an instance of the form.
0
 
jbettsAuthor Commented:
I am calling the above code in a button click event.  The Crystal report created is generated in a new window that opens up since I am using the .windowstate=crptmaximum and the iresult1=crystalreport1.printreport   This new window is separate from the form with the button that is clicked to generate the report.  The crystal report OLE control is on the same form as the generate report button (crystal icon not visible during run time-only design time).

I looked through the locals window while stepping through the program.  Everything related to crystal reports disappears from the locals window once the report is completed and closed.  I also do not find any type or reference in the locals window to the formulas that I am passing from VB into the crystal control.
0
 
DRRYAN3Commented:
At runtime are you closing the window which contains the report preview, or does your program call the three reports in succession?  If calling the three one after another, you may need to use 3 instances of the CrystalReport control in order to preview all three like that.
0
 
jbettsAuthor Commented:
No, I am not calling the 3 reports in succession.  Each report is called by a separate command button on the main form.  That is a good suggestion though, to use another crystal report OLE control on the form to run the other reports.  I would prefer to "reset" the crystal control between the report calls thou.
0
 
jbettsAuthor Commented:
Running from fewest to most forumulas does not produce error, only when running fewer after a greater formula report do I get the error.

The brute force method of clearing all formulas works.  Might have to bug the company into buying version 7+.  ;)

Thanks
0
 
DRRYAN3Commented:
If you upgrade, I think you'll be happy with the changes to the designer (things like aligning, changing widths).  Glad it's working now.

DRRYAN3
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.