multiple forms and a report

  • Thread starter Thread starter Miranda
  • Start date Start date
M

Miranda

hi,

i've got a form which can have muliple instances open - this/these forms
open a report in preview format through a button on click command

i've got the docmd.openreport....which all works fine but i want to set the
reports record source from the forms "openReport" button procedure.

now i've tried

reports!myReport.recordsource = " select....." before and after the
docmd.open...command but i get an error message saying the report is not
open yet if i put it before and if i put it after i get you cannot set the
recordsource of a report opened in preview format....

when can i set the recordsource? i can't do it in the reports onOpen command
because i need values that are on the open report form and there are
possibly muliple instances of the form open and i can't refer to it as
forms!reportPage!....

hope somebody can shed some light!
ta, miranda
 
You can only set the RecordSource of a report in its Open event.

You will therefore have to find a way to pass the values to the report. In
Access 2002 and later, you could use the OpenArgs of OpenReport to pass the
value(s). If there are multiple values, pass a delimited string, and parse
them into an arry in Report_Open by using the Split() function.

Another way to pass the values would be to set a public variable immediately
before the OpenReport, and then read the variable in Report_Open and store
the value(s) into local variables within the report's module.
 
I would assume that you avoided any query with direct refs to a form.

You can certainly pass the sql "where" clause when using the open report
command.

So, just remove any possible parameters, or form "refs" in your reports
query. Now, to restrict records...you use the "where" clause of the open
command.



dim strWhere as string

strWhere = "ProductID = " & me.ProductID
docmd.OpenReprot "MyReprot",acviewPreview,,strWhere

Using the above, you can pass any valid "where" clause to the reports
existing sql to resttrict, or tell what records the report should show.
 
Back
Top