Refresh calling form

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.
 
D

Douglas J. Steele

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
 
J

Jack Leach

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

JimS

Doug, I copied your code and pasted it. Looks like ControlType is not a
property of "ctl" as shown???
 
J

JimS

Good catch...also, you forgot the "then", but then I routinely do, too....


Thanks a bunch!
 
S

Stuart McCall

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.
 
D

Douglas J. Steele

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top