Solved Sub Form Requery a Query from another form

mloucel

Member
Local time
Today, 10:49
Joined
Aug 5, 2020
Messages
263
I have a form [F1], that contains a sub form [FSF1], the sub form has the results from a query [QueryView], will usually contain about 50 to 100 records.
[FSF1] is placed on the Sub Form as CONT Form.
Problem:

To make that [F1] work faster when I open another form [F2] I HIDE the form [F1]
When the other form closes, my last line of code is to UNHIDE [F1]
but I found a glitch
if I make changes to the DB with [F2] and return to [F1] those changes are NOT reflected since the query [QueryView] in [FSF1] does not re-query to reflect the latest changes
many times that is NOT required since other forms will not make any changes.

I've tried to follow instructions from this page:
How to refer to form and sub form [http://access.mvps.org/access/forms/frm0031.htm]

But I can't figure it out.

Forms!Mainform!Subform1.Form!Subform2.Form.QueryView.ReQuery

So how can I do a re query on [F1].[FSF1] before I un hide [F1] so when [F1] shows up again I can see the changes in [QueryView] ?

Any help will be appreciated.

Maurice.
 
Last edited:
Forms!Mainform!Subform1.Form!Subform2.Form.QueryView.ReQuery
It seems like you might not be aware that for this reference to function correctly, you would need to have the following structure:
  1. A main form named "Mainform".
  2. Within "Mainform", a subform control named "Subform1".
  3. Inside "Subform1", another subform control named "Subform2".
  4. Finally, within "Subform2", there should be a control named "QueryView".
Each level must be correctly named and placed as described for the reference to work.

Given that your main form is named "F1" and it contains a subform named "FSF1," the following references should work:
Forms.F1.FSF1.Requery
or
Forms!F1!FSF1.Requery
 
But I can't figure it out.
Try:
Code:
    If CurrentProject.AllForms("Your Main Form Name").IsLoaded = False Then Exit Sub

    Forms("Your Main Form Name").Controls("Your SubForm Control Name").Form.Requery
    'or
    'Forms("Your Main Form Name").YourSubFormControlName.Form.Requery
    
    Forms("Your Main Form Name").Visible = True
 
Try:
Code:
    If CurrentProject.AllForms("Your Main Form Name").IsLoaded = False Then Exit Sub

    Forms("Your Main Form Name").Controls("Your SubForm Control Name").Form.Requery
    'or
    'Forms("Your Main Form Name").YourSubFormControlName.Form.Requery
   
    Forms("Your Main Form Name").Visible = True
I think there is something missing, I got the following error:
Error.png


this I believe is telling me that the object in this case the name of the sub form is not found, and is because is still looking in the current form not in the hide form, I don't know how to tell access that needs to look in the HIDE form not in the current form.
 
It seems like you might not be aware that for this reference to function correctly, you would need to have the following structure:
  1. A main form named "Mainform".
  2. Within "Mainform", a subform control named "Subform1".
  3. Inside "Subform1", another subform control named "Subform2".
  4. Finally, within "Subform2", there should be a control named "QueryView".
Each level must be correctly named and placed as described for the reference to work.

Given that your main form is named "F1" and it contains a subform named "FSF1," the following references should work:
Forms.F1.FSF1.Requery
or
Forms!F1!FSF1.Requery
Did not work, access is looking within the current form and not in the hidden form, gave me the same error as I post in #4
 
Open the form you want to requery in design mode
Properties > Other > HasModule = true

Write Form_FSF1.Requery to requery the form.
 
When the other form closes, my last line of code is to UNHIDE [F1]
Post your code please
... and ...
try that code:
Code:
Dim objForm As Form
Dim objCtrl As Control
Const csHiddenFormName$ = "Your Hidden Form Name" ' <- Write your hidden form (with SubForm to update) name here
Dim sVal$
 
    If CurrentProject.AllForms(csHiddenFormName).IsLoaded = False Then
        DoCmd.OpenForm csHiddenFormName
        Exit Sub
    End If
 
    Set objForm = Forms(csHiddenFormName).Form
 
    For Each objCtrl In objForm.Controls
        If objCtrl.ControlType = acSubform Then
            objCtrl.Form.Requery 'Update found subForm
            sVal = "Your SubForm Control named: [" & objCtrl.Name & "] - is updated!"
            Debug.Print sVal
            MsgBox sVal, vbInformation
            Exit For
        End If
    Next
    Forms(csHiddenFormName).Visible = True
 
    Set objCtrl = Nothing
    Set objForm = Nothing
 
Last edited:
Post your code please
... and ...
try that code:
Code:
Dim objForm As Form
Dim objCtrl As Control
Const csHiddenFormName$ = "Your Hidden Form Name" ' <- Write your hidden form (with SubForm to update) name here
Dim sVal$
 
    If CurrentProject.AllForms(csHiddenFormName).IsLoaded = False Then
        DoCmd.OpenForm csHiddenFormName
        Exit Sub
    End If
 
    Set objForm = Forms(csHiddenFormName).Form
 
    For Each objCtrl In objForm.Controls
        If objCtrl.ControlType = acSubform Then
            objCtrl.Form.Requery 'Update found subForm
            sVal = "Your SubForm Control named: [" & objCtrl.Name & "] - is updated!"
            Debug.Print sVal
            MsgBox sVal, vbInformation
            Exit For
        End If
    Next
    Forms(csHiddenFormName).Visible = True
 
    Set objCtrl = Nothing
    Set objForm = Nothing
Eugene a million thanks, I am thinking with a bit of modification to make it a function so I can use it in a few other places that now have more possibilities thanks to your code, but for now I need to continue.

Thank you so much, works like a charm.
 
I suggest you post a sample db that reflects your current setup.
Thank you so much Edgar, I appreciate your kind help, @Eugene-LS was able to provide me with code that solved my issues and went a bit beyond what I needed, check his code on post #7.

Have a great day.
 

Users who are viewing this thread

Back
Top Bottom