New topic:
Passing the name of a report.. {Solved sorta -see post #3}
<http://forums.realsoftware.com/viewtopic.php?t=44016>
Page 1 of 1
[ 3 posts ] Previous topic | Next topic Author
Message comcents Post subject: Passing the name of a report..
{Solved sorta -see post #3}Posted: Tue May 15, 2012 9:48 am
Joined: Mon Apr 11, 2011 12:42 am
Posts: 57 Is there a way to pass the name of a report?
In the example "orders" report project - the preview and print methods are
passed a "steering" variable that is then used in a select case to establish
rs (record set) and rpt (report) - each "case" hard coded for each report to be
printed. What I would like to do is make the preview and print methods
"generic" and passing to them what they need. I discovered that the rs gets
"run to the end" by the preview - so has to be "refreshed" before being used in
the print method (else you get a page containing only the header and footer
stuff). That is easily solved by just putting the search stuff into an
"SelectSQL" variable, passing that to both routines and let them do a rs =
App.WaterWorxData.SQLSelect(App.SelectSQL) to generate a fresh rs in each
method. That works just fine.
Where I'm running into a problem is passing the report name to be used in the
methods. Hard coded it's (for one specific report) dim rpt as new CustDeposits
What I'd LIKE to do is dim rpt as new app.theReport where app.theReport is a
shared variable = CustDeposits (or whichever report is to be run). I've tried
casting app.theReport as a string - but RB complains "There is no class with
this name". OK so it's a report - so I tried casting it as a Report - then RB
still complains "There is no class with this name".
So is there a way to pass the reports' name(s) to the methods? or am I stuck
using a "steering variable" and hard coding for each report?
I'll admit - now that I'm *finally* starting get a glimmer of understanding
OOP/RB - I like it - but then I run into things like this that remind me how
much more I've got to learn...
Thanks for any help!
Randy G
Last edited by comcents on Wed May 16, 2012 8:55 am, edited 2 times in
total.
Top comcents Post subject:
Re: Passing the name of a report... Trying to simplify thinPosted: Tue May 15,
2012 12:18 pm
Joined: Mon Apr 11, 2011 12:42 am
Posts: 57 comcents wrote:Is there a way to pass the name of a
report?
In the example "orders" report project - the preview and print methods are
passed a "steering" variable that is then used in a select case to establish
rs (record set) and rpt (report) - each "case" hard coded for each report to be
printed. What I would like to do is make the preview and print methods
"generic" and passing to them what they need. I discovered that the rs gets
"run to the end" by the preview - so has to be "refreshed" before being used in
the print method (else you get a page containing only the header and footer
stuff). That is easily solved by just putting the search stuff into an
"SelectSQL" variable, passing that to both routines and let them do a rs =
App.WaterWorxData.SQLSelect(App.SelectSQL) to generate a fresh rs in each
method. That works just fine.
As a followup to my own post: In the above I contended that the record set rs
was being "run to the end" by the preview routine - then when the print routine
used rs - being at the end of the rs - only header and footer were printed. My
solution was to "refresh" rs by having each (preview and print) issue their own
rs=(query). To prove the point - I moved the initial query to the menu handler,
only now assigning the results to the shared app.ReportRecordSet. With
App.ReportRecordSet substituted for rs in both the Preview code and Print code
methods, this works - except of course the print routine again prints only
header and footer. If my theory about "why" is right - then the addition of
app.ReportRecordSet.MoveFirst should fix the problem - and it does. As you can
see - IF passing the REPORT can be made to work - then each menu handler for
each report - would set up both the record set and report - eliminating the
need for any hard-coded "steering code" in the preview and print modules.
Here is another question - if I can't pass the report name - how about making
the report (rpt) a shared variable - that is assigned in the menu handler...
(i.e. app.rpt)??? I'll try that... hope it doesn't blow up.
Thanks
Randy G.
BTW - I see by lack of quick answers to my original question - report name
passing appears to indeed be a "missing" feature - not me being stupid... that
makes me feel a little better!.
Top comcents Post subject:
Re: Passing the name of a report... Trying to simplify thinPosted: Tue May 15,
2012 12:59 pm
Joined: Mon Apr 11, 2011 12:42 am
Posts: 57 comcents wrote:Here is another question - if I can't
pass the report name - how about making the report (rpt) a shared variable -
that is assigned in the menu handler... (i.e. app.rpt)??? I'll try that...
hope it doesn't blow up.
Didn't blow up - never got that far - RB can't tell (in context) what
app.theReport is. So it never got passed the analysis / parser. However-
considering it can see app.theReport to make an assignment to it - I tried two
more things - at the start of each routine - I assigned rpt = app.theReport
and suddenly the Preview routine worked - though the print routine balked.
Seems it didn't like the now "not new" theReport. So set up another shared
variable thePreview and now I have my fully independent reports module working.
Here is the code:
First - menuhandler for the report:
app.theReport = new CustDeposits
app.thePreview = New CustDeposits
App.ReportRecordSet = App.WaterWorxData.SQLSelect("SELECT Acct, Name, Deposit
FROM Customer WHERE Deposit > 0")
windReports.showmodal
Return True
Then the preview code:
Dim ps As New PrinterSetup
Dim rpt as report
rpt = App.thePreview
if App.ReportRecordSet = nil then
beep
MsgBox "No records found to print."
else
If rpt.Run( App.ReportRecordSet,ps) Then
If rpt.Document <> Nil Then ReportViewer1.SetDocument( rpt.Document )
End If
end if
And finally the print code:
Dim ps As New PrinterSetup
Dim rpt as report
rpt = app.theReport
app.ReportRecordSet.MoveFirst // Restore the cursor to first record.
if App.ReportRecordSet = nil then
beep
MsgBox "No records found to print."
else
'set the resolution to 300 DPI for printing
ps.MaxHorizontalResolution = 300
ps.MaxVerticalResolution = 300
If ps.PageSetupDialog Then
dim g as graphics
g = OpenPrinterDialog(ps, nil)
if g <> nil then
If rpt.Run( app.ReportRecordSet, ps ) Then 'if the report runs successfully
rpt.Document.Print(g)
End If
end if
end if
end if
Anyone see any potential problems with this down the road?
Now - simply setting theReport, thePreview and ReportRecordSet in the menu
handler - no additional code need be written to add any number of reports...
(and I have near 60 to do. Sure -- I realize - a small handful have variables
for fields-- those will require different handling - but for the 50+ "regular
reports" - this just made my task a LOT easier)...
***-> While this works - the thing that still bothers me is why I have to do
the "hand-off" assignment of app.theReport (or app.thePreview) for the above to
work. If you use app.theReport rather than rpt in the above code - such as If
rpt.Run( app.ReportRecordSet, ps ) Then 'if the report runs successfully
rpt.Document.Print(g)
the parser says that app.theReport.Run object doesn't exist - (same with
rpt.Document.Print - the parser says app.theReport.document doesn't exist). I
guess it get's confused with the external reference app. in those instances -
**but should it**??? is that a bug?
Thanks
Randy G.
Top Display posts from previous: All
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost
timeSubject AscendingDescending Page 1 of 1
[ 3 posts ]
--
Over 1500 classes with 29000 functions in one REALbasic plug-in collection.
The Monkeybread Software Realbasic Plugin v9.3.
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml
[email protected]