Home > Archive > Visual Basic Crystal Reports > June 2005 > Using VBA to Pass a Variable
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Using VBA to Pass a Variable
|
|
|
| Hi All,
I am using Microsoft Access as the database to populate a Crystal Report.
Using VBA (and RDC) I can open the report and print it (either to a PDF or
the Printer, etc.) without too much problem.
What I would like to do is be able to pass a variable that changes the
Header in the Crystal Report. I was going down the path of just changing the
Text of the Text Object in Crystal but I am having a problem with that. I
have found the Help files for RDC for Crystal 10, but I am using 9. Is there
that much of a difference? Where could I get the RDC Help file for Crystal
9?
If anyone could show me a little code of how to pass a variable (in VBA) to
a text box it would be greatly appreciated.
Thanks so much.
-Gummy
| |
|
| Instead of trying to change the text of a Text object (which can be
done), it would be easier to use a formula that represents the header
text, and change the formula field's text at runtime.
For example, if at design time, you create a formula named
"ReportHeader" with the text of:
"This is my report header"
.... at runtime, you could do something like the following to change the
formula to whatever you want:
Dim strHeader As String
strHeader = "This is my new report header"
ReportObject.FormulaFields.GetItemByName("ReportHeader").Text = "'" &
strHeader & "'"
If you use a Text object, unless you know the name of the object (which
you can set in the designer by right-clicking on the text object >
Format Text > and set the Object Name), you would have to loop through
the ReportObjects collection to find your text object. If you did name
the Text Object, then you could avoid the demonstrated formula method
above, and do this (assuming the text object's Object Name is
"ReportHeader", and the text object is in the Report Header section):
Dim strHeader As String
strHeader = "This is my new report header"
'This next line looks in the ReportHeader section of the report
' for an object named 'ReportHeader', and sets its text...
ReportObject.Sections("RH").ReportObjects("ReportHeader").SetText strHeader
As for a Help file for the CR9 RDC, in my opinion, the best thing you
can do is download the RDC Browser utility:
http://support.businessobjects.com/...browser.exe.asp
| |
|
| Dave,
I can't begin to thank you enough. This was the perfect information that I
was looking for. I was so stuck and now I have a much better way of creating
these reports.
I still need to look more closely at the Browser utility, but that too looks
like it is going to answer my Crystal prayers.
If I dare ask another question...
When I print the report (to a PDF), it takes a little time for Crystal to
summarize and then print out the data, which is not a problem. But is there
a way (maybe looking at an event) to determine when the report has actually
been printed, compiled, or sent to the printer/pdf file?
Thank you so much, I really apprecaite the detailed directions and guidance.
"dave" <vidrutek@hotmail.com> wrote in message
news:rZ1ne.35056$6k7.22565@bignews4.bellsouth.net...
> Instead of trying to change the text of a Text object (which can be
> done), it would be easier to use a formula that represents the header
> text, and change the formula field's text at runtime.
>
> For example, if at design time, you create a formula named
> "ReportHeader" with the text of:
> "This is my report header"
>
> ... at runtime, you could do something like the following to change the
> formula to whatever you want:
>
> Dim strHeader As String
> strHeader = "This is my new report header"
> ReportObject.FormulaFields.GetItemByName("ReportHeader").Text = "'" &
> strHeader & "'"
>
> If you use a Text object, unless you know the name of the object (which
> you can set in the designer by right-clicking on the text object >
> Format Text > and set the Object Name), you would have to loop through
> the ReportObjects collection to find your text object. If you did name
> the Text Object, then you could avoid the demonstrated formula method
> above, and do this (assuming the text object's Object Name is
> "ReportHeader", and the text object is in the Report Header section):
>
> Dim strHeader As String
> strHeader = "This is my new report header"
> 'This next line looks in the ReportHeader section of the report
> ' for an object named 'ReportHeader', and sets its text...
> ReportObject.Sections("RH").ReportObjects("ReportHeader").SetText
strHeader
>
> As for a Help file for the CR9 RDC, in my opinion, the best thing you
> can do is download the RDC Browser utility:
>
http://support.businessobjects.com/...browser.exe.asp
| |
|
| Dave,
When I set the text in my title I use the format:
Report1.txttitle1.SetText strHeader
Where report1 is my report name
and txttitle1 is my text object
I am using VB6 and CR9 (RDC).
PJ
"dave" <vidrutek@hotmail.com> wrote in message
news:rZ1ne.35056$6k7.22565@bignews4.bellsouth.net...
Instead of trying to change the text of a Text object (which can be
done), it would be easier to use a formula that represents the header
text, and change the formula field's text at runtime.
For example, if at design time, you create a formula named
"ReportHeader" with the text of:
"This is my report header"
.... at runtime, you could do something like the following to change the
formula to whatever you want:
Dim strHeader As String
strHeader = "This is my new report header"
ReportObject.FormulaFields.GetItemByName("ReportHeader").Text = "'" &
strHeader & "'"
If you use a Text object, unless you know the name of the object (which
you can set in the designer by right-clicking on the text object >
Format Text > and set the Object Name), you would have to loop through
the ReportObjects collection to find your text object. If you did name
the Text Object, then you could avoid the demonstrated formula method
above, and do this (assuming the text object's Object Name is
"ReportHeader", and the text object is in the Report Header section):
Dim strHeader As String
strHeader = "This is my new report header"
'This next line looks in the ReportHeader section of the report
' for an object named 'ReportHeader', and sets its text...
ReportObject.Sections("RH").ReportObjects("ReportHeader").SetText strHeader
As for a Help file for the CR9 RDC, in my opinion, the best thing you
can do is download the RDC Browser utility:
http://support.businessobjects.com/...browser.exe.asp
| |
|
| Gummy:
Try something like this:
'Print the report
crxRpt.PrintOut False
'Loop until the printing has completed, or the progress has changed
Do While crxRpt.PrintingStatus.Progress = crPrintingInProgress
DoEvents
Loop
'When you're here, either the report has been printed, cancelled, _
or there was an error
You can use the CRPrintingProgress enum to determine the progress:
crPrintingNotStarted = 1
crPrintingInProgress = 2
crPrintingCompleted = 3
crPrintingFailed = 4
crPrintingCancelled = 5
crPrintingHalted = 6
The PrintingStatus might work for exporting as well. I haven't tried it,
so I can't say for sure.
PJ:
That method will only work for me if the report was created within the
VB IDE (i.e. as a .dsr), not if I'm calling the report from an external
file (.rpt).
| |
|
| Dave,
I thought Gummy indicated that he was using RDC.
PJ
"dave" <vidrutek@hotmail.com> wrote in message
news:9E8ne.49141$CR5.31915@bignews1.bellsouth.net...
Gummy:
Try something like this:
'Print the report
crxRpt.PrintOut False
'Loop until the printing has completed, or the progress has changed
Do While crxRpt.PrintingStatus.Progress = crPrintingInProgress
DoEvents
Loop
'When you're here, either the report has been printed, cancelled, _
or there was an error
You can use the CRPrintingProgress enum to determine the progress:
crPrintingNotStarted = 1
crPrintingInProgress = 2
crPrintingCompleted = 3
crPrintingFailed = 4
crPrintingCancelled = 5
crPrintingHalted = 6
The PrintingStatus might work for exporting as well. I haven't tried it,
so I can't say for sure.
PJ:
That method will only work for me if the report was created within the
VB IDE (i.e. as a .dsr), not if I'm calling the report from an external
file (.rpt).
| |
|
| PJ wrote:
> I thought Gummy indicated that he was using RDC.
>
> PJ
Yes, but using RDC doesn't necessarily mean that you're using the
designer within the VB IDE. Frankly, I never use it that way, as it
means that the .exe has to be compiled whenever a report needs updating.
|
|
|
|
|