Access run code in SubReport while opening main report


I have VBA code to populate a ListBox in an Access subreport . I an trying to run
the code  in this SubReport but getting the error shown below. The main report is called "rptInvoice"

Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gustav BrockCIOCommented:
Have in mind, that first the subreport opens, then closes, then the main report opens, and finally the subreport opens again.
That can cause some issues.

Also, oPopulate_ListBox must be declared Public.
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Also, as I mentioned in your earlier question, you cannot directly refer to a Subreport (or Subform), since it's not a member of the Reports collection. You instead have to refer to the Parent report first, then go from there. The syntax is like this:


ParentReport is the main report (the "parent")

SubReportCONTROLName is the name of the Subcontrol report on the parent report. It may or may not be named the same as the report you're using as a subreport.

For example, If my parent report is named rCustomer and my subreportCONTROL is name srpLocations (which uses a report named rLocations as the subreport):


This would run a method named CalculateValue on the report name rLocations, which is being hosted in a subreport control name srpLocations.

Confused yet :) ?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ste5anSenior DeveloperCommented:
Just a comment: What's the use of a ListBox in a report?

I prefer just querying the data already in the data source itself.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Hi Ste5an. The ListBox is there for the [Invoice Detail]. The rest of the form is there for the [Invoice] table
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks very much
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
The ListBox is there for the [Invoice Detail]
That's generally done with a standard Subreport instead of a Listbox on a Subreport.
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks Scott
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.