Indirect form reference

F

Fredrated

Is it possible to refer to a form indirectly and request an action?

I have a main form with several subforms which I need to requery when a
record is added to the main database table.

Presently, after a record is added, in the code I run
Form_fMain.HOUSING.Requery
Form_fMain.CAPITAL.Requery
Form_fMain.LANDUSE.Requery
Form_fMain.TRANSIT.Requery
Form_fMain.fMisc1.Requery
Form_fMain.fMisc2.Requery
Form_fMain.TechnicalAssistance.Requery
Form_fMain.Requery

Since subforms come and go, I would like to have the form names read from a
table and requeried from the name in the table.

Is there any way to do this?

Thanks
Fred
 
B

bcap

Form_fMain(string_expression).Requery

Where string_expression is anything that evaluates to the name of a form,
e.g it could be a variable or a field in a recordset.

But, what's the point? Since the last thing you are doing is requerying the
main form, that will cause all the subforms to be requeried anyway. In
other words, you're requerying 'em twice!
 
M

Marshall Barton

Fredrated said:
Is it possible to refer to a form indirectly and request an action?

I have a main form with several subforms which I need to requery when a
record is added to the main database table.

Presently, after a record is added, in the code I run
Form_fMain.HOUSING.Requery
Form_fMain.CAPITAL.Requery
Form_fMain.LANDUSE.Requery
Form_fMain.TRANSIT.Requery
Form_fMain.fMisc1.Requery
Form_fMain.fMisc2.Requery
Form_fMain.TechnicalAssistance.Requery
Form_fMain.Requery

Since subforms come and go, I would like to have the form names read from a
table and requeried from the name in the table.


Before going into your question, you need to understand that
the syntax you are using to reference the form objects (both
main a subforms) is not all that valid. Form_whatever
refers to the default instance of whatever, which is not
necessarily the one object you want to manipulate.

In general, you should refer to the main form using either
Me or Forms!fMain or Forms("fMain") The form objects used
as subforms should be referenced through the containing
subform control (without knowing the name of the actual form
object being displayed by the subform control's SourceObject
property). The syntax is Me.[subform control].Form or
Me("subform control") so your idea of storing the names of
the form objects used in subform controls has no relevance.
You would have to store the names of the subform controls
instead and use the syntax Me(recordset!field).Form

But, with all that in mind, what do you gain by putting the
names in a table? Whenever you modify a form to add/remove
a subform *control*, you have to remember to make a
corresponding change in the table.

If I wanted to have a generic procedure to manipulate
subforms, I think I would use the subform control's Tag
property to identify them. The procedure could then look
like:
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.Tag = "SubA" Then
ctl.Form.Requery
End If
Next ctl
 
F

Fredrated

Thanks, that was a lot more than I asked for, but it was information I needed!

Marshall Barton said:
Fredrated said:
Is it possible to refer to a form indirectly and request an action?

I have a main form with several subforms which I need to requery when a
record is added to the main database table.

Presently, after a record is added, in the code I run
Form_fMain.HOUSING.Requery
Form_fMain.CAPITAL.Requery
Form_fMain.LANDUSE.Requery
Form_fMain.TRANSIT.Requery
Form_fMain.fMisc1.Requery
Form_fMain.fMisc2.Requery
Form_fMain.TechnicalAssistance.Requery
Form_fMain.Requery

Since subforms come and go, I would like to have the form names read from a
table and requeried from the name in the table.


Before going into your question, you need to understand that
the syntax you are using to reference the form objects (both
main a subforms) is not all that valid. Form_whatever
refers to the default instance of whatever, which is not
necessarily the one object you want to manipulate.

In general, you should refer to the main form using either
Me or Forms!fMain or Forms("fMain") The form objects used
as subforms should be referenced through the containing
subform control (without knowing the name of the actual form
object being displayed by the subform control's SourceObject
property). The syntax is Me.[subform control].Form or
Me("subform control") so your idea of storing the names of
the form objects used in subform controls has no relevance.
You would have to store the names of the subform controls
instead and use the syntax Me(recordset!field).Form

But, with all that in mind, what do you gain by putting the
names in a table? Whenever you modify a form to add/remove
a subform *control*, you have to remember to make a
corresponding change in the table.

If I wanted to have a generic procedure to manipulate
subforms, I think I would use the subform control's Tag
property to identify them. The procedure could then look
like:
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.Tag = "SubA" Then
ctl.Form.Requery
End If
Next ctl
 

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