Avatar of stephenlecomptejr
stephenlecomptejr
Flag for United States of America asked on

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.Form.Requery
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].Requery
Me![sfTimeSheetWeekly].Visible = True

Open in new window


But I need to manipulate it from outside the main form.
Microsoft OfficeMicrosoft AccessVBA

Avatar of undefined
Last Comment
Mark Edwards

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Jim Dettman (EE MVE)

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Mark Edwards

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Mark Edwards

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:
Forms("fMainMenuTimeSheetMonthly").sfTimeSheetWeekly.Form.Requery
stephenlecomptejr

ASKER
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
stephenlecomptejr

ASKER
Appreciate the replies.  Sorry for the confusion.  Should have posted (and read) the error message - not just say it wasn't working.  LOL.
Your help has saved me hundreds of hours of internet surfing.
fblack61
stephenlecomptejr

ASKER
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"
Forms(sFormName).sfTimeSheetWeekly.Form.Requery 

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 (EE MVE)

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

Forms(sFormName)(ssfFormName).Form.Requery

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.

Jim
Mark Edwards

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:
objSubform.Requery

I've tested it and it works!
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.