0
votes

My PrintReport funtion works, but I want to print the report directly from PowerBuilder to the default printer without creating a dialog box. How can I accomplish this? Also can I specify a page range at the same time?

I use Crystal Reports 11.5 and PowerBuilder 12.5.

2

2 Answers

0
votes

PowerBuilder does not have a 'PrintReport' method. Not sure if this is something in your application code or in Crystal. If you are printing a datawindow, you can check the Print Specifications - Prompt Before Printing option.

0
votes

1- Declare instance variables in the window you are working

String module
String Folder,  FileName
Datawindow theDw

OLEObject g_ole_crx_application
OLEObject g_ole_crx_report
OLEObject g_ole_crx_connection_info
OLEObject g_ole_crx_export_options
OLEObject g_ole_crx_report_controls

String gs_rpt_filename, queryString, report_folder, report_file

OLEObject myoleobject

Long gi_return

//Please remove those variables you dont need

2- Paste following in any control (for example button)

String LoadFrom, LoadFile="C:\BT\SVN\Crystal\PB\app_reports_by_company_module.rpt" 
Integer Object_Id

g_ole_crx_application = CREATE OLEObject

gi_return  = g_ole_crx_application.ConnectToNewObject('CrystalDesignRunTime.Application.11')

if gi_return < 0 then

      MessageBox("Error", "Not connected to Crystal report")
      return

else

      gs_rpt_filename = LoadFile
      g_ole_crx_report = g_ole_crx_application.OpenReport(gs_rpt_filename) 

//Returns 0 if the report file does not exist or if an error occurs.

end if

queryString = g_ole_crx_report.ApplicationName  
g_ole_crx_connection_info =
g_ole_crx_report.database.tables[1].ConnectionProperties 
g_ole_crx_connection_info.deleteAll 


//g_ole_crx_report_controls = g_ole_crx_report.PageGenerator.Pages

String ConnectInfo = ""

//after deleting connection properties , add new connection properties
g_ole_crx_connection_info.add("Data Source", SQLCA.ServerName)
g_ole_crx_connection_info.add("Initial Catalog", SQLCA.Database)
g_ole_crx_connection_info.add("Database Type", "OLE DB (ADO)")
g_ole_crx_connection_info.add("Provider", "SQLNCLI10")
g_ole_crx_connection_info.add("User ID", SQLCA.logid)
g_ole_crx_connection_info.add("Password", SQLCA.logpass)
ConnectInfo += "Provider='SQLNCLI10';Data Source='"  + SQLCA.ServerName + "';"
ConnectInfo += "Initial Catalog='" + SQLCA.Database + "';DatabaseType='OLE DB (ADO)';"
ConnectInfo += "User ID=" + SQLCA.logid + ";Password=" + SQLCA.logpass
g_ole_crx_connection_info.add("ConnectInfo", ConnectInfo)

g_ole_crx_report.database.Verify 

//add parameters if there are any

//g_ole_crx_report.ParameterFields.GetItemByName("comp_code").AddCurrentValue('C001')

// here is the way how you can send print to the printer without print dialog box

// first set printer 

g_ole_crx_report.SelectPrinter("HP LaserJet 2200 Series PCL 5","HP LaserJet 2200 Series PCL 5", "LPT1")

// now use the PrintOut method 

g_ole_crx_report.PrintOut (FALSE, 1, TRUE, 1, 1)

// if you have insertable control to view crystal report you can use ReportSource and ViewReport

// i have it in a tab page with the name ole_view

// make sure you also set the source

//tab_1.tp_preview.ole_view.object.ReportSource(g_ole_crx_report)
//tab_1.tp_preview.ole_view.object.ViewReport



// Reference pdf : Crystal Reports XI Technical Reference Guide

// that will work hopefully