Crystal Report Viewer error ?

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


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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"

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
What database and how are you connecting.  I think Azra is on the correct track.

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
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

7of9121098Author Commented:
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.
On which line are you getting the error?  Does it get through the above line?
7of9121098Author Commented:
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....
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])
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.

7of9121098Author Commented:
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.

You can split the points but no biggy.  Glad it worked for you.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.