Open 'related' report from form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Let's say i have a form named "d_elist" and a report named the same (d_elist).
Let's say that the form is opened.
Is there a way to make a macro (or VB code) that when run opens the report
with the same name as the opened form (like d_elist), if any?
aka all my forms have a corresponding report with the same as the form. I
want to make a generic macro that opens the report with the same name of the
opened report.

Why? to filter the report without having to make seperate queries or forms
to design & apply a filter.

PS Any other way to come around this is welcome.

PS 2 Is there a way to implicitly call a property's value from a macro? aka
it is possible to implicitly call a field for the active object such as
[namefield] but is it possible for a property value?
 
Dimitri,

Not quite sure how you intend to fire the code (or macro) to do it;
bymeans of a command button on the form? Or what? nayway, as long as
it's fired from a form event and the code is in the form's own module,
the code is simply:

DoCmd.OpenReport Me.Name, acViewNormal

to print directly, or

DoCmd.OpenReport Me.Name, acViewPreview

to preview.

If the code is fired outside the form while the form in question is the
active one, then it would look something like:

DoCmd.OpenReport Forms(ActiveForm).Name, acViewNormal

(or acViewPreview).

By the way, just guessing here, but if the different reports actually
share the same design and the same overall recordsource, just having
different filters, you could (and should) use one report only, applying
the filter on opening. The same probably goes for the forms.

HTH,
Nikos
 
By the way, just guessing here, but if the different reports actually
share the same design and the same overall recordsource, just having
different filters, you could (and should) use one report only, applying
the filter on opening. The same probably goes for the forms.

Nikos,
The issue is the same with the post regarding the dued union query as you
proposed. Different forms, different report thus different filters.

I want to make a global button on a toolbar (active for all forms), that
when pressed, it copies the filter from the form to the report that has the
same name, and opens it (filtered on according to the form filter).

All that, is to use less code and less objects to do things where the only
thing that changes is the object reference.

hope this got it cleared up!.

Thanx again for all the help!
 
Dimitri,

Then the approach is the second one I proposed:

DoCmd.OpenReport Forms(ActiveForm).Name, acViewNormal

(or acViewPreview)

The filter: "copies the filter from the form to the report" is rather
general; pls be more specific if you need further help with it.

Nikos
 
The filter: "copies the filter from the form to the report" is rather
general; pls be more specific if you need further help with it.

the filter property value of the form is pasted into the filter property
value of the report so as the records displayed in the report, reflect the
(filtered) records seen on the form.
 
Dimitri,

Try this:

frm = Forms(Activeorm).Name
fltr = Forms(Activeform).Filter
DoCmd.OpenReport frm, acViewPreview, , fltr

HTH,
Nikos
 
Back
Top