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

export CR to word automatically 1

Status
Not open for further replies.

Hueby

MIS
Oct 20, 2004
321
0
0
US
In my VB.Net 03 app I have a form with a Crystal Reports Viewer, using CR 10. From there user's can preview/print the report, etc. I want to run the report and store the report on the hard drive automatically. Where do I begin this?

I currently use this code below in the form load event (it just previews the report for now) ... Is it simply modifying some of this? Any help or examples would be great!
CODE
Dim param1Fields As New CrystalDecisions.Shared.ParameterFields

Dim param2Field As New CrystalDecisions.Shared.ParameterField
Dim param2Range As New CrystalDecisions.Shared.ParameterDiscreteValue

param2Field.ParameterFieldName = "@variable"

param2Range.Value = variable

param2Field.CurrentValues.Add(param2Range)

param1Fields.Add(param2Field)

CrystalReportViewer1.ParameterFieldInfo = param1Fields
CrystalReportViewer1.ReportSource = "c:\Program Files\report"

CrystalReportViewer1.Refresh()

-- This is some code to export a CR to a Word document. Has anyone done this before? Any help merging this code, or how it can work together..?

Code:
   crExportOptions = crReportDocument.ExportOptions
        With crExportOptions
            .DestinationOptions = crDiskFileDestinationOptions
            .ExportDestinationType = ExportDestinationType.DiskFile
            .ExportFormatType = ExportFormatType.PortableDocFormat
        End With

        crReportDocument.Export()
 
Hi, try setting up a ReportDocument object and use its ExportToDisk method:

Dim oRpt As New ReportDocument

oRpt.ExportToDisk(CrystalDecisions.[Shared].ExportFormatType.WordForWindows, "c:\Program Files\reportname.doc")

Hope this helps.
 
Code:
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared

Dim oDir As New DiskFileDestinationOptions
Dim oExp As ExportOptions

'Export File Format
oExp = crReport.ExportOptions
oExp.ExportDestinationType = ExportDestinationType.DiskFile
oExp.ExportFormatType = ExportFormatType.WordForWindows
oDir.DiskFileName = "c:\test.doc"

oExp.DestinationOptions = oDir
crReport.Export()


Sweep
...if it works dont mess with it
 
Thanks everyone, but I'm confused on how to declare the report for 'crReport.' ... How do I transfer it from the crystalreportviewer ?

I tried 'CrystalReportViewer1.ExportOptions' with no luck.
 
Hi,
Hope this clarifies it.

Imports CrystalDecisions.CrystalReports.Engine
Dim oRpt As New ReportDocument

'Load your report
oRpt.Load("c:\YourDirectory\fileName.rpt")
'Set the source for your viewer
CrystlReportViewer1.ReportSource = oRpt

'Save the report
oRpt.ExportToDisk(CrystalDecisions.[Shared].ExportFormatType.WordForWindows, "c:\Program Files\reportname.doc")

 
udo321! thank you very much, that clears it up for me. Just wasn't clicking... THANK YOU
 
Well, it was working fine for a bit, now I'm getting this error:"An unhandled exception of type 'CrystalDecisions.CrystalReports.Engine.ParameterFieldCurrentValueException' occurred in crystaldecisions.reportappserver.datasetconversion.dll"

Additional information: Missing parameter values.

The code I'm currently using is:

Code:
        Dim FileName As String
        Dim Today As String
        Today = Format(Now, "mmddyyyy")

        Dim oRpt As New ReportDocument
        oRpt.Load("C:\Program Files\System2\rpts\HWIC\rptTMreceipt2.rpt")

        Dim param1Fields As New CrystalDecisions.Shared.ParameterFields

        Dim param2Field As New CrystalDecisions.Shared.ParameterField
        Dim param2Range As New CrystalDecisions.Shared.ParameterDiscreteValue
        Dim param3Field As New CrystalDecisions.Shared.ParameterField
        Dim param3Range As New CrystalDecisions.Shared.ParameterDiscreteValue

        param2Field.ParameterFieldName = "@startDate"
        param3Field.ParameterFieldName = "@endDate"

        param2Range.Value = F9.RstartDate.Text
        param3Range.Value = F9.RendDate.Text

        param2Field.CurrentValues.Add(param2Range)
        param3Field.CurrentValues.Add(param3Range)
        param1Fields.Add(param2Field)
        param1Fields.Add(param3Field)

        CrystalReportViewer1.ParameterFieldInfo = param1Fields 'to pass parameter inf.to CRV

        CrystalReportViewer1.ReportSource = oRpt
        CrystalReportViewer1.Refresh()

        oRpt.ExportToDisk(CrystalDecisions.[Shared].ExportFormatType.PortableDocFormat, "c:\TEMP\test.pdf")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top