Need MS Access VBA code to requery subform while open in a main form.

I need the correct syntax for a Microsoft Access VBA set of code that would allow a main form - requery a subform's information.
This used to work for me in the past (Access 2000-2013) but I'm using Office 365 now.

Forms!fMainMenuTimeSheetMonthly!sfTimeSheetWeekly.Visible = True

Open in new window

Primarily I have a lot of Me.Controls("txtBox1") in the subform to control from the main form.

This works within the subform itself:

Me![sfTimeSheetWeekly].Visible = True

Open in new window

But I need to manipulate it from outside the main form.
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.

Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:


 is correct.   Just watch that sfTimeSheetWeekly is the name of the sub form *control*, not the name of the subform.


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
Mark EdwardsChief Technology OfficerCommented:
I'm using Office 365 Access (2013 and 2016) and I have no problem requiring a subform with this:

If this doesn't work for you, I'd like to say tuned and see why.  I don't know of any reason why a change from store-bought Access to O365 Access would change this behavior.
Mark EdwardsChief Technology OfficerCommented:
Come to think of it, I think I remember an issue between using the bam (!) and using the dot (.) between form and control names.  (A change?)
I've also had this work fine:
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

stephenlecomptejrAuthor Commented:
You know what it actually was.  I was calling this from within the subform only..... and thus the main form wasn't open... thus the error... can't find the main form.

My apologizes.  But if it comes up - at least this will be in the search
stephenlecomptejrAuthor Commented:
Appreciate the replies.  Sorry for the confusion.  Should have posted (and read) the error message - not just say it wasn't working.  LOL.
stephenlecomptejrAuthor Commented:
Hey Mark,

I see how you could pass a variable name as the form with that above code doing:

Dim sFormName as String
sFormName = "fMainMenuTimeSheetMonthly"

Open in new window

But how do you also pass the subform name along with the formname in as a variable with the above?
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
<<But how do you also pass the subform name along with the formname in as a variable with the above>>

  You want control name, and it would be:


and a small fact; under the hood, Access converts all references to this format, which it then executes.   So using this format is actually a tad faster as it won't have to translate.

and a lot of objects will support that syntax.

Mark EdwardsChief Technology OfficerCommented:
If you want to combine them as one name, you could set the subform as an object variable.  For example:
Dim objSubform as form
Set objSubform = Forms("fMainMenuTimesheetMonthly").sfTimesheetWeekly.form
Then all you have to do is use the object variable:

I've tested it and it works!
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 Office

From novice to tech pro — start learning today.