Programmatically access the data in a report in design view

J

JustinP

I am using code to add text boxes to a report and need to access the
data for the current record (this data will dictate how many text boxes
to create). Having opened the report in design view how do I do this?

70 DoCmd.OpenReport "DummyReport", acViewDesign

80 i = 1
90 strSplit = Split(Reports!DummyReport!txtDummyBox.Value, "|")
<<<WHAT GOES HERE?

100 Do Until i = UBound(strSplit)

110 ctlTxtBox = CreateReportControl(DummyReport, acTextBox,
acGroupLevel1Header, "", intTxtBoxLeft, intTxtBoxTop + 600,
intTxtBoxWidth, intTxtBoxHeight)

120 Loop

130 DoCmd.OpenReport "DummyReport", acViewPreview
 
A

Allen Browne

Justin, the approach you are taking will not prove to be useful.

Firstly, reports don't have a "current record." There may be none at all
(depending how the report is filtered), or there may be one, or there may be
many. You can try to examine the RecordSource of the report, to see what
record(s) might be likely to arrive, but the report could be filtered so
that approach is flawed. Further, even if you did manage to OpenReport with
a WhereCondition, Access will set the Filter property to reflect that, but
(unlike forms), it fails to maintain the FilterOn property for reports
correctly. Consequently, you cannot tell whether the Filter is genuine
(actually to be applied) or an artifact of a previous open.

You should also be aware that most serious developers ultimately want to
retain at least the chance to use an MDE. Anything that requires design view
is not going to work with an MDE.

Ultimately there is a finite number of controls you can place on the report.
So, why not put the maximum number you could ever need on the report now,
and then show/hide/resize them in Report_Open to whatever you need? You can
even show/hide/resize them in Detail_Format if the report really demands
that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top