Reset Crystal Report from VB6.0

Posted on 2001-08-06
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??
Question by:jbetts
  • 6
  • 5
LVL 12

Expert Comment

ID: 6355890
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?

Author Comment

ID: 6356101
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

    MsgBox "Some other error " & Err.Number & Err.Description, vbOKOnly + vbExclamation, "Print Error"
End Sub
LVL 12

Expert Comment

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


after your .ReportFileName line.  The current versions do support a reset method.
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.


Author Comment

ID: 6356401
Tried the discardsaveddata ---- didn't work.  Tried that line a few places in code.  No go.
LVL 12

Expert Comment

ID: 6357138
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.

Author Comment

ID: 6357233
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.
LVL 12

Expert Comment

ID: 6357272
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.

Author Comment

ID: 6359422
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.
LVL 12

Accepted Solution

DRRYAN3 earned 200 total points
ID: 6359835
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.

Author Comment

ID: 6360014
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+.  ;)

LVL 12

Expert Comment

ID: 6360168
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.


Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Join issues with Crystal Report 10 69
Select Cross-tab total 2 62
Crystal Reports No Record Returned 2 51
Crystal reports filter out records 2 27
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…
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

813 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

12 Experts available now in Live!

Get 1:1 Help Now