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

Exporting a report 1

Status
Not open for further replies.

5340fazi

Programmer
Nov 4, 2003
5
DK
Hello,
I am using crystal reports 9 with VB 6 .0 . I want to export the report on a form load. For this purpose I have designed a report in crystal designer. Then I have used the flowing code to generate the file. It creates the world file but file does not contains any data. But if I preview of the report then it shows me the data. I have tried a lot. Please some one tells me why this is happening. Thanks in advance fazi


Dim Report As New CrystalReport1
Dim crApp As New CRAXDDRT.Application
Dim crRep As New CRAXDDRT.Report


Private Sub Form_Load()

'Export to disk
' Location of the report
Set crRep = crApp.OpenReport(App.Path & "/Reports/Myreport.rpt")

Report.ExportOptions.DestinationType = crEDTDiskFile
'Export to Microsoft Word format
Report.ExportOptions.FormatType = crEFTWordForWindows
'Export path and file name
Report.ExportOptions.DiskFileName = "c:\MyReport.doc"
'Export without displaying the 'Export' dialog box
Report.Export False

End Sub
 
It doesn't appear that you are logging onto your database. Is your report saved with data and therefore no connection is necessary? Or are you running your report against a database that doesn't require a logon?

Also, why are you using CRAXDDRT? If you are using an external report file (i.e., not a report that exists in a DSR), you probably should be using CRAXDRT.
 
My report is not saved with data. My database is MS access. Can u give me the code which helps me. fazi
 
Ok, upon reviewing your code, you've got some real confustion going on.

Let's look at your code:

"Dim Report As New CrystalReport1" This line would be used to create a new report object based on a DSR (i.e., a crystal report contained within the vb app).

But then you create another report object:

Dim crRep As New CRAXDDRT.Report
...
Set crRep = crApp.OpenReport(App.Path & "/Reports/Myreport.rpt")

So which report object are you trying to use? crRep or Report? Which is the real report? The remainder of your code doesn't use crRep. It uses Report, which would be pointing to the DSR report in vb.

Do you understand the difference between the two report objects you've created?

 
I am understand the probelm.As u said earlier that if i am getting data from database then i need to connect to database can u tell me how i can do that in vb. using report object. If u can give me a exmaple with source code then it will be grate help for me. with regrdas fazi
 
Before I can give you accurate code, I need to know which report it is you want to use? Are you using the report that is located at?:

App.Path & "/Reports/Myreport.rpt")

If so, you probably don't need to logon to the MS Access database (unless you have a password assigned to the database). As long as the Access mdb file is located in the same place as when you designed the report, you'll be fine.

If you are using the report in the path noted above, then the following code should allow you to export the report:


Dim crApp As New CRAXDDRT.Application
Dim crRep As CRAXDDRT.Report


Private Sub Form_Load()

'Export to disk
' Location of the report
Set crRep = crApp.OpenReport(App.Path & "/Reports/Myreport.rpt")

crRep.ExportOptions.DestinationType = crEDTDiskFile
'Export to Microsoft Word format
crRep.ExportOptions.FormatType = crEFTWordForWindows
'Export path and file name
crRep.ExportOptions.DiskFileName = "c:\MyReport.doc"
'Export without displaying the 'Export' dialog box
crRep.Export False

Many examples of coding Crystal with vb can be found at the Crystal Decisions website. Download the following for more information:


Another note: unless you are using the DSR file (CrystalReport1), you should remove the DSR from your vb project and add a reference to the Crystal Reports ActiveX Designer Runtime Library. Then remove the Reference to the Crystal Reports ActiveX Designer Design and Runtime Library. Change the first two lines of code that create the report and application objects to:

Dim crApp As New CRAXDRT.Application
Dim crRep As CRAXDRT.Report
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top