Here is the code I am using. I am trying to display the printer dialog box instead of displaying the report. I set the isdisplaypage property of the viewer to true and the report displays and the printer dialog box appears and you print and it works correctly. If I set the isdisplaypage to false the printer dialog box appears but when I try to print I get the error:
An communication error occurred. Printing will be stopped
Any suggestions with my code would be appreciated...
<%
const crFieldValueTypeInt8sField = 0
const crFieldValueTypeInt8uField = 1
const crFieldValueTypeInt16sField = 2
const crFieldValueTypeInt16uField = 3
const crFieldValueTypeInt32sField = 4
const crFieldValueTypeInt32uField = 5
const crFieldValueTypeNumberField = 6
const crFieldValueTypeCurrencyField = 7
const crFieldValueTypeDateField = 9
const crFieldValueTypeTimeField = 10
const crFieldValueTypeStringField = 11
const crFieldValueTypeDateTimeField = 15
const crFieldValueTypeUnknownField = 255
If Session("IsReportServerRunning") Then
Call Session("crReportViewer").ProcessHttpRequest(Request, Response, Session)
Else
Session("IsReportServerRunning") = True
Dim dbServer, dbDatabase, dbUser, dbPassword
dbServer = Session("ReportServerDataSource")
dbDatabase = Session("ReportServerDBDatabase")
dbUser = Session("ReportServerDBUserName")
dbPassword = Session("ReportServerDBPassword")
If Not IsObject(Session("crSessionManager")) Then
Set Session("crSessionManager") = Server.CreateObject("CrystalEnterprise.SessionMgr")
If Err Then Session("strMsg")="Cannot Create Crystal Enterprise Server component: SessionMgr"
End IF
If Not IsObject(Session("crEnterpriseSession")) Then
Set Session("crEnterpriseSession") = Session("crSessionManager").Logon(Session("ReportServerUserID"), Session("ReportServerPassword"), Session("ReportServerCMS"), Session("ReportServerAut"))
If Err Then Session("strMsg")="Cannot Connect User " + Session("ReportServerUserID") + " to Crystal Enterprise Server"
End IF
If Not IsObject(Session("crIStore")) Then
Set Session("crIStore") = Session("crEnterpriseSession").Service("", "InfoStore")
If Err Then Session("strMsg")="Cannot Create Crystal Enterprise Server component: InfoStore"
End IF
If Not IsObject(Session("crReportAppFactory")) Then
Set Session("crReportAppFactory") = Session("crIStore").EnterpriseSession.Service("", "RASReportFactory")
If Err Then Session("strMsg")="Cannot Create Crystal Enterprise Server component: RASReportFactory"
End IF
If Not IsObject(Session("crObjectFactory")) Then
Set Session("crObjectFactory") = Server.CreateObject("CrystalReports10.ObjectFactory.1")
If Err Then Session("strMsg")="Cannot Create Crystal Enterprise Server component: ObjectFactory.1"
End IF
'If Not IsObject(Session("crReportViewer")) Then
Set Session("crReportViewer") = Nothing
Set Session("crReportViewer") = Session("crObjectFactory").CreateObject("CrystalReports.CrystalReportViewer")
If Err Then Session("strMsg")="Cannot Create Crystal Enterprise Server component: CrystalReportViewer"
Dim reportID, reportDocument
reportID = GetReportID(Session("ReportServerReportName"),Session("ReportServerAppFolder"),Session("ReportServerREAFolder"))
If IsNull(reportID) Then
Response.Write "This report cannot be found on Crystal Server Enterprise. Please contact your network administrator.<BR>"
Response.Write "Report Name is " & "/" & Session("ReportServerAppFolder") & "/" & Session("ReportServerREAFolder") & "/" & Session("ReportServerReportName")
Response.End
End IF
Set reportDocument = GetReportDocument(reportID)
If Session("strMsg")="" Then LaunchPageViewer reportDocument
End If
Function GetReportID(strReportName, strMainFolder, strSubFolder)
Dim result, mainFolderID, subFolderID
Set result = Session("crIStore").Query("Select SI_ID, SI_NAME From CI_INFOOBJECTS Where SI_PROGID='CrystalEnterprise.Folder' And SI_NAME = '" + strMainFolder + "'")
If result.ResultCount = 1 Then
mainFolderID = result.Item(1).ID
Else
GetReportID = Null
Exit Function
End If
Set result = Session("crIStore").Query("Select SI_ID, SI_NAME From CI_INFOOBJECTS Where SI_PROGID='CrystalEnterprise.Folder' And SI_NAME = '" + strSubFolder + "' And SI_PARENT_FOLDER = " + cstr(mainFolderID))
If result.ResultCount = 1 Then
subFolderID = result.Item(1).ID
Else
GetReportID = Null
Exit Function
End If
Set result = Session("crIStore").Query("Select SI_ID, SI_NAME From CI_INFOOBJECTS Where SI_PROGID='CrystalEnterprise.Report' And SI_NAME = '" + strReportName + "' And SI_INSTANCE = 0 And SI_PARENT_FOLDER = " + cstr(subFolderID))
If result.ResultCount = 1 Then
GetReportID = result.Item(1).ID
Else
GetReportID = Null
Exit Function
End If
End Function
Function GetReportDocument(reportID)
Set GetReportDocument = Session("crReportAppFactory").OpenDocument(reportID)
End Function
Sub LaunchPageViewer(reportDocument)
' change the connection with the database for main report and subreports
For Each crTable In reportDocument.DatabaseController.Database.Tables
reportDocument.DatabaseController.SetTableLocationByServerDatabaseName crTable.Alias, dbServer, dbDatabase, dbUser, dbPassword
Next
Dim crConnectionInfo
Set crConnectionInfo = reportDocument.DatabaseController.FindConnectionInfoByDBServerName(dbServer)
' loop all subreports and change the connection with database
Dim strSubs, strSubreportname, crDatabase, crTable
Set strSubs = reportDocument.SubreportController.QuerySubreportNames
For Each strSubreportname In reportDocument.SubreportController.QuerySubreportNames
Set crDatabase = reportDocument.SubreportController.GetSubreportDatabase(strSubreportname)
For Each crTable In crDatabase.Tables
crTable.ConnectionInfo = crConnectionInfo
crTable.ConnectionInfo.UserName = dbUser
crTable.ConnectionInfo.Password = dbPassword
reportDocument.SubreportController.SetTableLocation strSubreportname, crTable, crTable
Next
Next
'view the report in the viewer
Dim strReportExportName
strReportExportName=Session("ReportServerReportName")
With Session("crReportViewer")
.ReportSource = reportDocument.ReportSource
.IsOwnForm = True
.IsOwnPage = True
.PrintMode = 1
.IsDisplayPage = False
.IsDisplayGroupTree = False
End With
' pass the parameters to report and subreports
Dim crParamField, iParam, arraynb, iLngIndex
For iParam = 0 To Session("crReportViewer").ParameterFields.Count - 1
Set crParamField = Session("crReportViewer").ParameterFields.Item(iParam)
crParamField.CurrentValues.RemoveAll
crParamField.AllowMultiValue = True
If InStr(Session("ReportServerParams")(iParam),",") <= 0 Then
Redim arraynb(1)
arraynb(0) = Session("ReportServerParams")(iParam)
End If
Select Case crParamField.Type
Case crFieldValueTypeNumberField:
For iLngIndex=0 To ubound(arraynb)
If arraynb(iLngIndex) <> "" Then
crParamField.CurrentValues.Add(clng(arraynb(iLngIndex)))
End If
Next
Case crFieldValueTypeCurrencyField:
For iLngIndex=0 To ubound(arraynb)
crParamField.CurrentValues.Add(ccur(arraynb(iLngIndex)))
Next
Case crFieldValueTypeDateField:
For iLngIndex=0 To ubound(arraynb)
crParamField.CurrentValues.Add(cdate(arraynb(iLngIndex)))
Next
Case crFieldValueTypeDateTimeField:
For iLngIndex=0 To ubound(arraynb)
crParamField.CurrentValues.Add(cdate(arraynb(iLngIndex)))
Next
Case crFieldValueTypeStringField:
For iLngIndex=0 To ubound(arraynb)
crParamField.CurrentValues.Add(cstr(arraynb(iLngIndex)))
Next
Case Else
For iLngIndex=0 To ubound(arraynb)
crParamField.CurrentValues.Add(cstr(arraynb(iLngIndex)))
Next
End Select
Next
Call Session("crReportViewer").ProcessHttpRequest(Request, Response, Session)
End Sub
Dim currentViewState
Set currentViewState = Request.Form("CrystalCompositeViewState")
'Response.Write "The current view state is: " & currentViewState
'If the view state exists, this is the first iteration of the code and so output the javascript to initiate the print control.
if currentViewState = "" then
%>
<script language="javascript">
<!--
CrystalEvent("CrystalViewer", "tb=crprint");
// --> </script>
<% else
%>
<script language="javascript">
<!--
window.close();
// -->
</script>
<% end if %>