Accessing (!) subform controls properties at runtime

A

AlexT

Folks

I am trying to develop a semi generic form that I fine tune at runtime.

I other words I have a form called frmGeneric. When relevant I
instantiate a new form based on frmGeneric and, before making it
visible, I setup some properties (such as fields names, record source,
etc) at run time.

This works great so far but I am having a problem with a subForm
embedded into the main form. As per my above strategy, I will have to
access the subForm controls before displaying it... But how should I
reference those controls ?

Say lstObj is my subform, from the container form code module in the
LOAD envent I would be tempted to use

Me.lstObj.Form.Controls(aCtl).Caption = "something"

where aCtl is the name of a control in the sub form

But this fails...

(The expression you entered refers to an object that is closed or
doesn't exist.)

It's probably trivial but I can't seem to find the "right way"
of doing this

Any help welcome
 
G

Guest

Hy AlexT,

You don't need to use the Controls collection to access the controls on the
subform.
You have to use this code:

Me.Subform.Forms!ControlName.PropertyName
 
A

AlexT

Hi

thanks for your mnesage... which actualy raises more questions...

:)

To start with your alternate syntax doesn't work either - same
problem.

But even if it were to work I need a way to access the subform controls
using an *indirection* (i.e. assigning the name of the control to a
variable and then use the value of that variable to get to the
control).

Now my problem seems to be that because I instantiate a *new* form
based on the existing one, I can't seem to be able to access it's
subform... which incidentally does not appear on screen either assuming
I make my newly created form visible...

So even Me.lstObj.Form.Controls(1).name fails...

One more question... How should I interpret the "!" notation (as
per your example Me.Subform.Form!ControlName.PropertyName) ? I'm an
Excel guy and not too familiar with what seems to be an Access only
operator ?!

Thanks for your help and patience

--alexT
 
G

Guest

In Access syntax, you separate parts of your object references using either
the bang (!) character or the dot (.) character.
When to use bang and when to use dot depends on the context of its use. In
general:
Use the . (dot) to refer to a member or property that is created and
maintained by Microsoft Access.
Use the ! (bang) to refer to a member or property that you create.
 

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