Crystal Report Viewer error ?

Posted on 2003-12-10
Last Modified: 2012-06-27
In Vb I run the following code with no errors but when I run the code
it gives me the error dialog box "Server has not yet been Opened" on
the CR Viewer.
How do I fix this?

Set Report = CrystalRPT.OpenReport("c:/temp/crystalreports/xyz.rpt")

Report.RecordSelectionFormula = "{x}=0"

CRViewer1.ReportSource = Report


Question by:7of9121098
  • 4
  • 3
  • 2
  • +1
LVL 28

Accepted Solution

AzraSound earned 50 total points
ID: 9916651
I encountered this problem before as well and finally just initiated the connection to the database myself, e.g.,

Set Report = CrystalRPT.OpenReport("c:/temp/crystalreports/xyz.rpt")
Report..Database.LogOnServer "p2sodbc.dll", "ServerName", "DatabaseName", "Username", "Password"
LVL 100

Expert Comment

ID: 9917651
What database and how are you connecting.  I think Azra is on the correct track.


Expert Comment

ID: 9917853
You made your .rpt file in the CR IDE and now are opeing it in VB?

If you open a .rpt file that has data saved with it (does yours?) the report tries to connect to the data source that was used when you created the report.  I had that message before and I think it was the order of the statments.

I love the results of ccrystal reports but had a hard time pinning down all the syntax.

here is a paste from a project that used .rpt files, set their datasource at run time and dynamicaly created the reports.  VB6 SP5, CR8.5, Access DB, No report designer in project - Maybe that will help.  Good luck.

Private Sub L_SpawnCRView()
  Dim i As Integer, j As Integer
  Dim LInt_RepCount As Integer
  Dim CRXReport As CRAXDRT.Report
  Dim ff
  'On Error GoTo errhandle
  If hfg_reports.Rows = 0 Then Exit Sub
  Screen.MousePointer = vbHourglass
  'Create a new child viewer form - Find free index or increase array
  LInt_RepCount = GF_CRV_Form_New()
  'tag and caption for new viewer child form
  CRV_Form(LInt_RepCount).Caption = "Reporte #" & LInt_RepCount & " - " & hfg_reports.TextMatrix(hfg_reports.Row, 1)
  'Open our report template (*.rpt) and assign it to our Local report Object (file name based off label.caption)
  Set CRXReport = CRXApplication.OpenReport(GStr_ReportsPath & lbl_reportfilename.Caption)
  'Bind to current data
  Dim DBTable
  For Each DBTable In CRXReport.Database.Tables
    DBTable.Location = GStr_RootDataPath & GCStr_DBName_MergedPOS
  'assign report to Type CRV_FormState (we manipulate this to change scope in viewing)
  Set CRV_FormState(LInt_RepCount).ReportObject = CRXReport
  'Set attributes and default scope for this report (eg. tpye = 'otro' (needs to be there regardless of date scope we add later...)
  CRV_FormState(LInt_RepCount).ReportStyle = Val(hfg_reports.TextMatrix(hfg_reports.Row, 3))
  CRV_FormState(LInt_RepCount).DefaultFormula = CRV_FormState(LInt_RepCount).ReportObject.RecordSelectionFormula
  'CRV_FormState(LInt_RepCount).DefaultFormula = hfg_reports.TextMatrix(hfg_reports.Row, 6)
  'Assign report source to our report viewer
  CRV_Form(LInt_RepCount).CRViewer.ReportSource = CRV_FormState(LInt_RepCount).ReportObject
  'place sub-title
  For Each ff In CRV_FormState(LInt_RepCount).ReportObject.FormulaFields
    If ff.Name = "{@Title}" Then
      ff.Text = Chr$(34) & CRV_FormState(LInt_RepCount).DefaultFormula & Chr$(34)
    End If
  'View the report
  Do While CRV_Form(LInt_RepCount).CRViewer.IsBusy = True
  '/ Depending on the attributes of this report display the apropriate controls on the form
  If CRV_FormState(LInt_RepCount).ReportStyle > 0 Then
    CRV_Form(LInt_RepCount).chk_alldates.Visible = True
    CRV_Form(LInt_RepCount).cmb_GroupPeriodType.Visible = True
    CRV_Form(LInt_RepCount).cmb_GroupPeriodType.ListIndex = 1
    CRV_Form(LInt_RepCount).lbl_period.Visible = True
    'TO DO: Set DTPs to High and Low Ranges of availabe Records
    '       (not the stupid default value of the date when control was placed on form
    CRV_Form(LInt_RepCount).chk_alldates.Visible = False
    CRV_Form(LInt_RepCount).cmb_GroupPeriodType.Visible = False
    CRV_Form(LInt_RepCount).lbl_period.Visible = False
  End If

  Screen.MousePointer = vbDefault
  Set CRXReport = Nothing
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.


Author Comment

ID: 9917951
The following still gave me the same message..."Server has not yet been Opened" but no compiler errors, just at run time.

Report..Database.LogOnServer "p2sodbc.dll", "ServerName", "DatabaseName", "Username", "Password"

 I'm using SQL Server 7 as the database.
LVL 28

Expert Comment

ID: 9918269
On which line are you getting the error?  Does it get through the above line?

Author Comment

ID: 9918547
Yes it goes through the above line...error appears at this code...
Report..Database.LogOnServer "p2sodbc.dll", "ServerName", "DatabaseName", "Username", "Password"

Like it doesn't like it...the server and db etc is correct....

Expert Comment

ID: 9918946
Try passing the arguments as double quotes (empty strings) to use the default reports settings.  Maybe you can find the part that is not liked.

Or you could try LogOnServerEx

Sub LogOnServerEx (pDllName As String, pServerName As String,
[pDatabaseName], [pUserID], [pPassword],
[pServerType], [pConnectionString])

Expert Comment

ID: 9918962
Some other ideas...

Make sure the data you are connecting to is identical to the data your report was created with.  ie. no extra fields.

Also you could try someting like in my code where you assign the table.
There is a white papper on the subject at

Promisingly entitled "Crystal Reports ASP Reporting - Troubleshooting: 'Server Has Not Yet Been Opened' "

Im too tired to read it but it looks very thurogh.


Author Comment

ID: 9924053
Thanks guys Its working now...the code below was correct....but

Report..Database.LogOnServer "p2sodbc.dll", "ServerName", "DatabaseName", "Username", "Password"

  Wierd if I use the ServerName that is displayed in SQL Server or on the Network it gives me the error message "Server has not been...". But the Crystal Report uses the ODBC DSN for the ServerName under the "set location" button in Crystal Reports. So what I did as suggested in the article is to make sure the Servername matches with the CR with the VB code listed above.

P.S. I was I can give you credit to Ficus for the article and all of you guys but unfortuately I can't.


Expert Comment

ID: 9932913
You can split the points but no biggy.  Glad it worked for you.

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

776 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