Access run code in SubReport while opening main report

Hi

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"

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

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

x
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.
0
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:

Reports!ParentReport.SubReportCONTROLName.Report.SomePropertyOrMethod

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):

Reports!rCustomer.srpLocations.Report.CalculateValue

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

Confused yet :) ?
0

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.
0
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
0
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks very much
0
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.
0
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks Scott
0
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.