I am using VB6 and Crystal Report 9.0.
I need to export a Crystal Report file into a PDF file format by simply a click at an button on the VB form.
How can I code to export such file?
Thanks very much for the help!!!
Printable View
I am using VB6 and Crystal Report 9.0.
I need to export a Crystal Report file into a PDF file format by simply a click at an button on the VB form.
How can I code to export such file?
Thanks very much for the help!!!
Here is the code form one of my reports that extracts to a PDF fdile.
--/
Set Report = crxApplication.OpenReport("Z:\DAD\CertificateofComplianceB.rpt", 1)
For Each crxDatabaseTable In Report.Database.Tables
crxDatabaseTable.ConnectionProperties("user id") = "sa"
crxDatabaseTable.ConnectionProperties("Password") = myPasswordTechniSQL
Next crxDatabaseTable
Report.ExportOptions.FormatType = crEFTPortableDocFormat
Report.ExportOptions.DiskFileName = "C:\Certificate_of_Compliance_" & jobinx & ".pdf"
Report.ExportOptions.DestinationType = crEDTDiskFile
Report.Export False
--/
Sorry stanleyccs, for hijacking your thread but this may help you too because it is very similar to what you are doing.
Hi Pasvorto,
I am doing something very similar except I am exporting to HTML.
I am interested in your connection method.
I tried using your code but I am not familiar enough with the VB Code.
I can get my code to export a generic report that does not login to the SQL database but when I try my report the login portion fails.
I think my problem might be with the definition.
Here is my code:
Private Sub Command1_Click()
Dim crxApp As CRAXDRT.Application
Dim crxRpt As CRAXDRT.Report
Dim crxDatabaseTable As CRAXDRT.DatabaseTable
Set crxApp = New CRAXDRT.Application
Set crxRpt = crxApp.OpenReport("H:\VB6\SuSched\SuSched.rpt", 1)
For Each crxDatabaseTable In Report.Database.Tables
crxDatabaseTable.ConnectionProperties("user id") = "sa"
crxDatabaseTable.ConnectionProperties("Password") = test
Next crxDatabaseTable
With crxRpt.ExportOptions
.FormatType = CRAXDRT.CRExportFormatType.crEFTHTML40
.DestinationType = CRAXDRT.CRExportDestinationType.crEDTDiskFile
.HTMLFileName = "H:\VB6\SuSched\SuSched.html"
End With
crxRpt.Export (False)
Set crxRpt = Nothing
Unload Form1
End Sub
Edit: I forgot to tell you I would like to use an odbc connection.
Thanks - Jeff
I got it to work for me by adding:
With crxRpt.Database.Tables(1).ConnectionProperties
.Item("DSN") = "TEST"
.Item("Database") = "TEST_DB"
.Item("User ID") = "TESTUSER"
.Item("Password") = "PASSWORD"
End With
Thanks
What is the component or preferences needed to use
this command (ConnectionProperties) ??
I think it is the Crystal Reports ActiveX.
I am not 100% sure, I still a rookie.
I have these three references:
CRAXDRT (ActiveX)
CrystalDecisions.CrystalReports.Engine
CrystalDecisions.Shared
Crystal Reports Developer V 10 & VB.Net is what I am using.
Actually, I changed it to this (sorry if some lines wrap):
'Declare ActiveX objects
Dim crxApp As CRAXDRT.Application
Dim crxRpt As CRAXDRT.Report
Dim crxDatabaseTable As CRAXDRT.DatabaseTable
'Used for connection to the SQL Server using the ODBC DSN
Dim lstrDataSource As String
Dim lstrCatalog As String
Dim lstrUser As String
Dim lstrPassword As String
Dim lstrLocation As String
Dim lstrTableName As String
'Turn on hourglass
System.Windows.Forms.Cursor.Current = system.Windows.Forms.Cursors.WaitCursor
crxApp = New CRAXDRT.Application
'Set Logon properties
lstrDataSource = "MY_DSN"
lstrCatalog = "MY_DB"
lstrUser = "MY_USERNAME"
lstrPassword = "test"
'Open the report to export
crxRpt = crxApp.OpenReport("\\HPTLWF01\DPRTMNTS$\Information_ Systems\Visual Basic Progs\ExportSuSched.NET\SuSched.rpt", 1)
crxRpt.DiscardSavedData() 'We want a fresh query
'Connect to the database using ODBC connection
For Each crxDatabaseTable In crxRpt.Database.Tables
lstrTableName = crxDatabaseTable.Location
crxDatabaseTable.ConnectionProperties.DeleteAll() 'Clear existing connection properties
crxDatabaseTable.ConnectionProperties.Add("DSN", lstrDataSource) 'Set connection properties
crxDatabaseTable.ConnectionProperties.Add("Database", lstrCatalog)
crxDatabaseTable.ConnectionProperties.Add("User Id", lstrUser)
crxDatabaseTable.ConnectionProperties.Add("Password", lstrPassword)
Next crxDatabaseTable 'Loop through all the tables in the report
.....
How do I get VB to recognise CRAXDRT. If I do Dim crxApp As CRAXDRT.Application it says that craxdrt is undeclared
You need to add a reference to Crystal Reports x.x ActiveX Designer Run Time Library.