Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

An communication error occurred. Printing will be stopped

Status
Not open for further replies.

jasonhuibers

Programmer
Sep 12, 2005
290
CA
I am trying to print my report directly from the asp page rather than display the report. When I use IsDisplayPage = true the report appears and the printer dialog box is prompted as well. When I change .IsDisplayPage to = false to hide the viewer, the report does not appear and the printer dialog box appears but when I click Print I get

An communication error occurred. Printing will be stopped

Here is the viewer properties:
With Session("crReportViewer")
.ReportSource = reportDocument.ReportSource
.IsOwnForm = True
.IsOwnPage = True
.PrintMode = 1
.IsDisplayGroupTree = False
.HasCrystalLogo = False
.HasPageNavigationButtons = True
.HasExportButton = True
.HasRefreshButton = True
.HasSearchButton = True
.HasPrintButton = True
.HasGotoPageButton = True
.HasToggleGroupTreeButton = True
.HasViewList = False
.EnableParameterPrompt = False
.EnableLogonPrompt = False
.IsSeparatePages = True
.IsDisplayToolbar = True
.IsEnableDrillDown = False
.ReuseParameterValuesOnRefresh = True
.IsDisplayPage = false

End With
 
Hi,
When we had a similar problem, support recommended that we call the viewer on a separate asp page:

So we use,

'Declare the viewer object variable
Dim Viewer

'Create a viewer object and view the report
Set Viewer = CreateObject("CrystalReports.CrystalReportInteractiveViewer")
With Viewer
.reportSource = reportDocument
.HasBooleanSearchButton = False
.HasCrystalLogo = False
If NbrParams > 0 then
.ParameterFields = Fields
End If
.HasRefreshButton = True
.IsDisplayGroupTree = False
.HasPrintButton = true
.PrintMode = 0 ' disable activeX Printing - .IsOwnPage = true
End With
Set Session("viewer") = Viewer
'call new page to display report - workaround
Response.Redirect("viewprint.asp")

And viewprint.asp is:

<%
option explicit
dim viewer
set viewer = session("viewer")
'Error handle
on error resume next
Viewer.ProcessHTTPRequest Request, Response, Session

if err.number <> 0 then
response.write "Failed to view report" & "</BR>"
response.write "error number: " & err.number & "</BR>"
response.write "error description: " & err.description
end if
%>


See if it helps in your situation...




[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
I am passing parameters to my report and when I try your suggestion I get invalid parameter...

 
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 %>




 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top