Refresh calling form

  • Thread starter Thread starter JimS
  • Start date Start date
J

JimS

My main form opens a form that makes changes to the data bound to a subform
in my main form. Trying to keep everything as generic as possible, what I
want to do is something like this:

if strParentName <> "" Then
if CurrentProject.AllForms(strParentName).Isloaded Then
Forms(strParentName).Filter=Forms(strParentName).Filter (forces refresh)
For each <subform> in <Parent form reference>
<force a refresh of that subform>
Next <subform>
endif
endif

What's the syntax for the "for each..." structure?

The subform's record source is a query that calculates remaining quantities.
The Called Form alters those remaining quantities. There's also another
subform on the Main form with similar issues.
 
Dim ctl As Control

For each ctl in Forms(strParentName).Controls
If ctl.ControlType = acSubfrom
Forms(strParentName).Controls(ctl.Name).Form.Refresh
End If
Next ctl
 
Usually what I do here, to avoid looping controls and finding the ones that
are subforms, and to also avoid unneccesary refreshing of subforms, is
something along these lines:

Public Function RefreshSubform(strParent As String, strSubControl As String)
Forms(strParent).Controls(strSubControl).Requery
End Sub

I run this after the popup detail form is closed.

To answer your question though, a for/next loop might look like this:

Dim ctl As Control
For Each ctl In Forms(frmParentName)
If ctl.ControlType = acSubform (??? not sure if acSubform is correct)
ctl.Form.Refresh 'or maybe
ctl.Form.Requery 'or, you can just requery the control itself
ctl.Requery
End If
Next ctl


--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
Doug, I copied your code and pasted it. Looks like ControlType is not a
property of "ctl" as shown???
 
Forms(strParentName).Controls(ctl.Name).Form.Refresh

Doug

Any reason you see for this not to be just ctl.Form.Refresh ?

Not saying there's anything wrong with your code; just curious.
 
Stuart McCall said:
Doug

Any reason you see for this not to be just ctl.Form.Refresh ?

Not saying there's anything wrong with your code; just curious.

No reason at all, other than the fact it didn't occur to me at the time!
 
Back
Top