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

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?
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.


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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

747 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

13 Experts available now in Live!

Get 1:1 Help Now