Solved

Reset Crystal Report from VB6.0

Posted on 2001-08-06
11
2,948 Views
Last Modified: 2012-08-13
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??
0
Comment
Question by:jbetts
  • 6
  • 5
11 Comments
 
LVL 12

Expert Comment

by:DRRYAN3
Comment Utility
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
 

Author Comment

by:jbetts
Comment Utility
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
 
LVL 12

Expert Comment

by:DRRYAN3
Comment Utility
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
 

Author Comment

by:jbetts
Comment Utility
Tried the discardsaveddata ---- didn't work.  Tried that line a few places in code.  No go.
0
 
LVL 12

Expert Comment

by:DRRYAN3
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:jbetts
Comment Utility
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
 
LVL 12

Expert Comment

by:DRRYAN3
Comment Utility
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
 

Author Comment

by:jbetts
Comment Utility
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
 
LVL 12

Accepted Solution

by:
DRRYAN3 earned 200 total points
Comment Utility
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
 

Author Comment

by:jbetts
Comment Utility
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
 
LVL 12

Expert Comment

by:DRRYAN3
Comment Utility
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

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now