Directly printing Crystal Report.
I have Database Fields on my Crystal Report and want to directly print the .RPT file from Visual Basic 6, without importing the report, as a Form, in VB.
How to directly print the .RPT file and populate its Database Fields with records in a recordset?
Re: Directly printing Crystal Report.
Code:
'ADO objects are populated and open.
Set crxApp = New CRAXDRT.Application
Set moReport = New CRAXDRT.Report
Set moReport = crxApp.OpenReport(App.Path & "\MyReport.rpt", 1)
moReport.Database.SetDataSource goRs, 3, 1
moReport.DisplayProgressDialog = True
moReport.PrintOut True, 1
Then depending on your database, this will be for SQL server after the OpenReport method.
Code:
moReport.Application.LogOnServer "P2SSQL.DLL", sServer, sDatabase, sUserName, sUserPwd
moReport.Database.Tables(1).SetLogOnInfo sServer, sDatabase, sUserName, sUserPwd
Re: Directly printing Crystal Report.
Thanks RobDogg for the code. I have some more queries:
I am using Access XP MDB and its connection string looks like this:
Code:
"Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=false;
Data Source=" & App.Path & "\Data\cust.mdb;Jet OLEDB:Database Password='ProgramKey';
User ID='Admin'"
I have some more problem with password-protected MDB files. Kindly view
my this post too:
http://www.utteraccess.com/forums/sh...b=5&o=&fpart=1
Also illustrate how to pass the password to call Crystal Report.