Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Crystal Report Viewer error ?

Posted on 2003-12-10
Medium Priority
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
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
  • 4
  • 3
  • 2
  • +1
LVL 28

Accepted Solution

AzraSound earned 200 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 101

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
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…
Suggested Courses

610 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