PDA

Click to See Complete Forum and Search --> : Invoking Crystal From VB How?


Lafor
Sep 19th, 2003, 09:32 AM
Thanks in advance to all!

Would appreciate a quick response...

Thanks

RobDog888
Sep 19th, 2003, 12:28 PM
Add these references to to your project.
"Crystal Reports x.x ActiveX Designer Runtime Library"
"Crystal Data Object"
"Crystal Reports Expert"
"Crystal Reports x.x Library"
Then something like this to open the report and export the report as a .pdf file.
Option Explicit

Private Function SendReport(ByVal sWhere As String)

Dim oReport As CRAXDRT.Report
Dim crxApplication As New CRAXDRT.Application
Dim crxExportOptions As CRAXDRT.ExportOptions

Set crxApplication = New CRAXDRT.Application
Set oReport = crxApplication.OpenReport(App.Path & "\Report.rpt", 1)
oReport.RecordSelectionFormula = sWhere
Set crxExportOptions = oReport.ExportOptions
crxExportOptions.DestinationType = crEDTDiskFile
crxExportOptions.DiskFileName = App.Path & "Report " & Format(Now, "YYYY-MM-DD") & ".pdf"
crxExportOptions.FormatType = crEFTPortableDocFormat
crxExportOptions.PDFFirstPageNumber = 1
crxExportOptions.PDFLastPageNumber = 1
crxExportOptions.PDFExportAllPages = True

oReport.Export False

'Terminate Cleanly
Set oReport = Nothing
Set crxApplication = Nothing
Set crxExportOptions = Nothing

End Function

Lafor
Sep 19th, 2003, 01:16 PM
Thanks a mil...
The .pdf is created in the path of the application...
which I later opened

Any way to open on the fly?

RobDog888
Sep 19th, 2003, 01:18 PM
I suppose your could after the termination code use the file name
and shell Acrobat Reader with the file name as a parameter.

Lafor
Sep 19th, 2003, 01:19 PM
Thanks

Lafor
Sep 22nd, 2003, 02:31 PM
I am shelling acrobar reader...
I don't see the .pdf on the screen...
I have to go to the taskbar ang maximize... it to see it at all

Any ideas? Can't I just pop it on top?

Thanks in advance...

RobDog888
Sep 22nd, 2003, 02:49 PM
To shell Acrobat or program associated with the .pdf extension use...
Option Explicit

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, _
ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long

Const SW_SHOWNORMAL As Long = 1
Const SW_SHOWMAXIMIZED As Long = 3
Const SW_SHOWMINIMIZED As Long = 2

Private Sub cmdShellPDF_Click()
'WITH THE YOU CAN SET THE WORKING DIRECTORY TOO!
ShellExecute Me.hwnd, vbNullString, "D:\Test.pdf", vbNullString, "D:\", SW_SHOWMAXIMIZED
End SubLet me know if this was what you were describing.

Lafor
Sep 22nd, 2003, 03:18 PM
Thanks much....

RobDog888
Sep 22nd, 2003, 03:25 PM
Your welcome.
Glad to help.

Lafor
Sep 24th, 2003, 10:16 AM
I have a table with two fields ActivityDate and Event
How do I pass a parameter to the crystal report so that
it displays events not greater than x number of days old only..

Currently, the report is showing all events

Thanks

RobDog888
Sep 24th, 2003, 10:27 AM
Use the parameterfields of the oReport object. You need to clear
each parameter before you set a value to it, every time.
oReport.ParameterFields.Item(1).ClearCurrentValueAndRange
oReport.ParameterFields.Item(1).AddCurrentValue dActivityDate
oReport.ParameterFields.Item(2).ClearCurrentValueAndRange
oReport.ParameterFields.Item(2).AddCurrentValue sEvent

HTH

Lafor
Sep 24th, 2003, 11:07 AM
Bear with me

The report has subreports and is created external to VB
and I am exporting it into .pdf as u showed me and kick acrobat
to display it... Now, it is one of the subreborts for which I need
a parameter field... So the user could be prompted on the fly (if possible) to enter something and corresponding data would be displayed..

Do we add a parameter field to the individual report before
entering as a subreport...

I guess I am asking how does it all tie...together ?

Currently, my main report displays data for all organizations grouping them by OrgID then the subreport displays data just for the orgID being displayed.. But it's displaying all the activities for it since the beginning of time for the ORg.. What I'd like to do is to create a field that the client could enter a number like 30 enter and only last 30 days activity (for example) would be displayed..

I am probably verbose... But that happens when one has little time to do something with a new tool..

Thanks again

Lafor
Sep 25th, 2003, 09:55 AM
How does one refresh the report data frm within VB?

Thanks

RobDog888
Sep 25th, 2003, 10:07 AM
Since the report is exported out as a pdf file, the report can not
be refreshed unless you re-export the report.
You may want to look at using the Crystal Report Viewer control
in VB to allow you to view/export the report in real time.
Although if you are distributing the program ther may be licensing issues.


As far as the previous post, you need to create a parameter at
the main report level. Then link the parameter to the subreport
by reimporting the sub report. This will allow you to pass a
parameter to the report which will inturn go to the sub report.


HTH

Lafor
Sep 25th, 2003, 10:11 AM
always...

Thanks..

For the previous post
Even ReExporting does not seem to do it.. I'll check again...

As for the prior post..

I have decided to create stored procedures which accept parameters that populate a table with the data that I need and the report or subreport would then extract from that table..

Lafor
Sep 25th, 2003, 10:23 AM
Actually, the export would work if one opts to not save the data with the report....

Thanks

RobDog888
Sep 25th, 2003, 10:24 AM
In Crystal Reports, when you created the report, there is a
setting under File > Options > Reporting tab... called "Save data
withreport" checkbox. Uncheck it and resave your report. Also,
since you have a subreport, under the New Report tab there is
another checkbox to "Reimport subreport subreports when
opening reports". I'm not too sure if that is only for the
development enviroment or if it could affect your results.


HTH