
Crystal Reports 8.5/VBA "Server has not yet been opened" error.
I am using:
Windows 2000 Professional
Valid MS SQL 8.00.194 server
Valid ODBC Datasource with SQL Server authentication
Crystal Reports Developer 8.5.0.217
VBA 6
When trying to preview a report using the Crystal Reports Viewer
component in VBA, it works fine when I am either connecting to the
database, or using parameters. When using both, I get the "Server has
not yet been opened" error.
The code:
'-------------------------------------------------
Option Explicit
Dim crApplication As New CRAXDRT.Application
Dim crReport As CRAXDRT.Report
Public Sub doPrint(reportName As String, serverName As String, dbName
As_
String, dbUser As String, dbPassword As String)
Dim CRXParamDefs As CRAXDRT.ParameterFieldDefinitions
Dim CRXParamDef As CRAXDRT.ParameterFieldDefinition
Set crReport = crApplication.OpenReport("c:\reportName.rpt")
crReport.Database.Tables(1).SetLogOnInfo serverName, dbName, dbUser,
dbPassword
Set CRXParamDefs = crReport.ParameterFields
For Each CRXParamDef In CRXParamDefs
With CRXParamDef
Select Case .ParameterFieldName
Case "invoice_num"
.SetCurrentValue 111, crNumberField
End Select
End With
Next
crReport.EnableParameterPrompting = False
form1.CRViewer2.ReportSource = crReport
form1.CRViewer2.ViewReport
End Sub
'---------------------------------------------------
The culprit line seems to be ".SetCurrentValue 111, crNumberField".
Removing it removes the error and the report seems to load fine. When
the line is present, the CRViewer object stays blank and the error
pops up. The line "form1.CRViewer2.ViewReport" seems to be raising the
error.
The code seems to be working under 2 conditions:
1. I do not have the SetLogonInfo statement and use a static report
(no data from database).
2. I remove the parameter parts (more specifically, the line
'.SetCurrentValue 111, crNumberField'.
I have a single parameter in my report named "invoice_num" which is of
type "number".
In Crystal Reports, the report seems to access the database correctly
as it displays information from the DB in the preview tab.
There does not seem to be a similar error condition on the Crystal
Decisions website knowledge base.
Any help/suggestions/patch suggestions will be greatly appreciated!
thanks in advance
Neil