2 intances of the same report

G

Guest

hi
im trying to open the same report twice using vb code.
I tried to use DoCmd.OpenReport but when i write it twice, it still opens
only one instance.
How can i make more instances of the same report and present them ?
I used also :

Dim rpt As New Report_rptOrder
rpt.Visible = True

but it just flashes on the screen and closes.
 
A

Allen Browne

The New keyword is the approach you have to take.

But the report then depends on the variable you created. When the routine
exists, the variable is cleaned up, and so the report is closed. Since this
all happens very fast, you just see the report flash and disappear.

You therefore need a way to manage the various instances. You can do that
with a custom collection. But there is a problem. The whole point of opening
multiple instances of the same report object is that you want to filter them
differently. Since you are using the New keyword to generate them, there is
no WhereCondition like OpenReport has, so you must programmatically set the
Filter of each instance in its Open event. The trouble is that there is a
bug in how Access applies the filter, so it is likely to apply the filter to
the wrong instance. There is therefore no way to use multiple instances of
the same report reliably in Access.

This problem does not arise with forms, so if you are interested in the
technique of multiple instances, see:
Managing Multiple Instances of a Form
at:
http://allenbrowne.com/ser-35.html

For info about the Access bug:
Incorrect filtering of forms and reports
at:
http://allenbrowne.com/bug-02.html

The filter bugs that apply to forms are fixed in Access 2007. I have not yet
tested if the report problems are fixed in the new version yet. If you want
to test it for yourself, you can download the beta from:
http://microsoft.com/office/preview/beta/
 
G

Guest

Hi Allen,
Thank you very much for the detailed answer.
The reason I want to open multiple insances is not for filtering -
I'm producing an an invoice report, and I would like each time to produce a
source invoice and a copy invoice.
It's the same report exactly, only I need to change some captions on the
reports itself ("source" / "copy" etc...)
Maybe you have a better idea for this than multiple instances...?

Thanks.
 
A

Allen Browne

If you want 2 copies that are identical in layout, but one marked "source"
and the other marked "copy":

1. Create a table with one Text field named ReportType.
Mark it as primary key.
Save the table
Enter 2 records, for Source and Copy.

2. Create a query using the table(s) you want for your report.
Add the ReportType table as well.
There must be no join between this table and the others.
This will give you 2 of every recrord in your query.
Save. Close

3. Open your report in design view.
Set its RecordSource property to this query.
In the Sorting And Grouping box (View menu), insert a line above any others,
and choose the Report Type field. In the lower pane, choose Yes for the
Group Header. Access puts a new section towards the top of the report design
view. Add the ReportType field from the Field list (View menu) to this new
section.

The report will now give you 2 copies of everything: one marked Source, and
the other marked Copy.

In a case where you want only one, you can filter the report. If you want a
triplicate copy, add a 3rd record to the table.
 
G

Guest

Allen -
Thank you very much.
Nadav.

Allen Browne said:
If you want 2 copies that are identical in layout, but one marked "source"
and the other marked "copy":

1. Create a table with one Text field named ReportType.
Mark it as primary key.
Save the table
Enter 2 records, for Source and Copy.

2. Create a query using the table(s) you want for your report.
Add the ReportType table as well.
There must be no join between this table and the others.
This will give you 2 of every recrord in your query.
Save. Close

3. Open your report in design view.
Set its RecordSource property to this query.
In the Sorting And Grouping box (View menu), insert a line above any others,
and choose the Report Type field. In the lower pane, choose Yes for the
Group Header. Access puts a new section towards the top of the report design
view. Add the ReportType field from the Field list (View menu) to this new
section.

The report will now give you 2 copies of everything: one marked Source, and
the other marked Copy.

In a case where you want only one, you can filter the report. If you want a
triplicate copy, add a 3rd record to the table.
 
G

Guest

Allen,
Maybe you can tell me how to programatically change a text box's caption in
a report ?
i mean, on the "Open" event of the report, i'll have the code to change a
caption in the report.
I tried and it didn't work. (txtKind = "blabla" doesn't wotk).

Thanks.
 
A

Allen Browne

From memory, Report_Open is too early to assign a value to an unbound
control.

Try the Format event of the section the control is in.

Alternatively, right-click the text box in design view, and Change To |
Label.
In Report_Open, you will can set the Caption of a label, e.g.:
Me.[Label1].Caption = "blabla"
 
G

Guest

Allen,
Thanks man, u'r a big help.
btw - the Caption property for some reason doesn't appear in the
AutoComplete, you know, when u hit "." after the control's name. I tried the
same code only with "Text" instead of "Caption", who also doesn't appear
there... and it failed.
but u'rs is working... so thanks u.

Nadav.

Allen Browne said:
From memory, Report_Open is too early to assign a value to an unbound
control.

Try the Format event of the section the control is in.

Alternatively, right-click the text box in design view, and Change To |
Label.
In Report_Open, you will can set the Caption of a label, e.g.:
Me.[Label1].Caption = "blabla"

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Nadav said:
Allen,
Maybe you can tell me how to programatically change a text box's caption
in
a report ?
i mean, on the "Open" event of the report, i'll have the code to change a
caption in the report.
I tried and it didn't work. (txtKind = "blabla" doesn't wotk).

Thanks.
 

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