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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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.
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

724 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