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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to print directly to printer

Status
Not open for further replies.

nomi2000

ISP
Feb 15, 2001
676
CA
Hi
i am using following code in VB.net Crystal Report for .Net
how can i implement to print report directly on printer instead of showing in the Control
Thanks
Nouman
Dim intTables, intParamCount As Integer

' Objects used to set the proper database connection information
Dim tbCurrent As CrystalDecisions.CrystalReports.Engine.Table
Dim tliCurrent As CrystalDecisions.Shared.TableLogOnInfo

Dim pvCollection As New CrystalDecisions.Shared.ParameterValues()
Dim pdvParameter As New CrystalDecisions.Shared.ParameterDiscreteValue()

' Create a report document instance to hold the report
Dim rptDocument As New ReportDocument()

Try
Select Case strReportName
Case Is = "A" '7501 Report

' Load the report
'rptExpensiveProducts.Load("..\Reports\rptCustomEntry.rpt")
rptDocument.Load("..\Reports\rptCustomsEntryNew.rpt")

For Each tbCurrent In rptDocument.Database.Tables
tliCurrent = tbCurrent.LogOnInfo
With tliCurrent.ConnectionInfo
.ServerName = ReportServerName
.UserID = DBUserName
.Password = Password
.DatabaseName = ReportDatabaseName

End With
tbCurrent.ApplyLogOnInfo(tliCurrent)
Next tbCurrent



pdvParameter.Value = ParamCollection.Item(1)

' Add it to the parameter collection.
pvCollection.Add(pdvParameter)

rptDocument.DataDefinition.ParameterFields("@P_CustomEntryID").ApplyCurrentValues(pvCollection)
pvCollection = New CrystalDecisions.Shared.ParameterValues()
pdvParameter = New CrystalDecisions.Shared.ParameterDiscreteValue()

pdvParameter.Value = ParamCollection.Item(2)
' Add it to the parameter collection.
pvCollection.Add(pdvParameter)
' Apply the current parameter values.
rptDocument.DataDefinition.ParameterFields("@P_CustomEntryShipmentID").ApplyCurrentValues(pvCollection)


'rptDocument.SetDataSource(RecordsetDataSet)
rptDocument.Database.Tables(0).SetDataSource(RecordsetDataSet.Tables(0))
rptDocument.Database.Tables(1).SetDataSource(RecordsetDataSet.Tables(1))
End Select

' Set the report source for the crystal reports
' viewer to the report instance.

'rptDocument.SetDataSource(RecordsetDataSet)
rptViewer.ReportSource = rptDocument

' Zoom viewer to fit to the whole page so the user can see the report
rptViewer.Zoom(150%)
 
In an ASP.NET app that I have I can do the following to print a report:

Dim Rep as new CrystalReport1
'Open the report first
.
.
'This is the name of the printer as it is defined on the server
Rep.PrintOptions.PrinterName = "Hp_laserjet1"
Rep.PrintToPrinter(1, False, 1, 999)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top