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

Can Crystal report be exported without viewer? 2

Status
Not open for further replies.

KerryC

Technical User
Apr 9, 2002
36
CA
I'm writing a Windows application that will be run from another application we use. I want the Windows program to create a text file from data in a Crystal report. The 1st application will supply a parameter to the Crystal report as a command line parameter. I have a test program written that will accept the command line parameter and show the report with the correct data in a Crystal Report Viewer control on the main form. However, I don't want to use a viewer, in fact I don't really want to use a form. Is this possible?

I've been going in circles through the help screens and can find examples of how to use parameters by building a paramFields object and associating it with the report viewer using:

ReportViewer.ParameterFieldInfo = paramFields

And I've seen an example of how to export a report without using a viewer, but I haven't seen any way to do both, ie get a report to open using a supplied command line parameter, and export it to a text file without using a report viewer.

Any and all help appreciated, thanks.

Kerry
 
You can use a report view and just not show it ;)

We have a series of automated reports that run in 'silent' mode every night. They use the exact same code as the manual version (including the form), except that they print automatically, instead of waiting for a user to hit 'OK'.

-Rick

----------------------
[banghead]If you're about to post an ASP.Net question,
please don't do it in the VB.Net forum[banghead]

[monkey] I believe in killer coding ninja monkeys.[monkey]
 
Rick - I think I'll have to give that a try.

Thank you.

Kerry
 
Eureka - it seems it is possible using vb.net to pass command line parameters to a crystal report and programatically export it without the use of a form or a report viewer control. I thought I'd post this in case it helps someone else someday. I slimmed the code down a tad for this example, but hopefully it still makes sense.

Sub Main(ByVal Arguments As String())
Dim SampleCode, ReportName, DestinationFile as string

'Put the command line parameters into named variables
SampleCode = Arguments(1).ToString
ReportName = Arguments(2).ToString
DestinationFile = Arguments(3).ToString

'Create a ReportDocument object
Dim crReportDocument As New ReportDocument

'Load the ReportDocument object with the crystal report named in the passed parameter
crReportDocument.Load(ReportName)

'Set the report parameter to the supplied sample code
crReportDocument.SetParameterValue("SampleCode", SampleCode)

'Set connection properties for the database
With crConnectionInfo
.ServerName = "MyServer"
.DatabaseName = "MyDatabase"
.UserID = "MyUserID"
.Password = "MyPassword"
End With

'Set the crTables to the Tables collection of the ReportDocument object
crTables = crReportDocument.Database.Tables

'Loop through each table in the report and apply the LogonInfo Information
For Each crTable In crTables
crtableLogonInfo = crTable.LogOnInfo
crtableLogonInfo.ConnectionInfo = crConnectionInfo
crTable.ApplyLogOnInfo(crtableLogonInfo)
Next

'Set up automatic export
Dim exportOpts As New ExportOptions
Dim diskOpts As New DiskFileDestinationOptions
exportOpts = crReportDocument.ExportOptions
'set the export format
exportOpts.ExportFormatType = ExportFormatType.RichText
exportOpts.ExportDestinationType = ExportDestinationType.DiskFile
diskOpts.DiskFileName = DestinationPath exportOpts.DestinationOptions = diskOpts

'Perform the export
crReportDocument.Export()
End Sub

Kerry
 
Kerry,

Thanks for your post! It was EXACTLY what I was looking for!!

Lloyd

Thanks and best regards,
-Lloyd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top