Associated labels and groups

V

Viarum

Is there any way you can access/detect programatically (vba) an associated
label from a textbox?
I have a similar question for groups. You can group controls in a form and
manipulate them together.
But how can such groups be accessed in vba? I am missing the collections that
exist e.g. in powerpoint.
Thank you for suggestions!
 
S

Stuart McCall

Answers inline:

Viarum said:
Is there any way you can access/detect programatically (vba) an associated
label from a textbox?

Yes, through the controls collection for the textbox, which, for a textbox
will only ever contain one 'child' control - ie the label, like this

Debug.Print Forms!Form1!Text1.Controls(0)
I have a similar question for groups. You can group controls in a form and
manipulate them together.
But how can such groups be accessed in vba? I am missing the collections
that
exist e.g. in powerpoint.
Thank you for suggestions!

If you mean group them in design view, then take a look at the InSelection
property.

If you mean access them in a loop from VBA at runtime, then its up to you to
name them consistently, like:

Textbox1, Textbox2, Textbox3 etc.

Then you can do:

For i = 1 To 3
Debug.Print me.Controls(Textbox" & i).Name
Next
 
S

Stuart McCall

Answers inline:

Viarum said:
Is there any way you can access/detect programatically (vba) an associated
label from a textbox?

Yes, through the controls collection for the textbox, which, for a textbox
will only ever contain one 'child' control - ie the label, like this

Debug.Print Forms!Form1!Text1.Controls(0)
I have a similar question for groups. You can group controls in a form and
manipulate them together.
But how can such groups be accessed in vba? I am missing the collections
that
exist e.g. in powerpoint.
Thank you for suggestions!

If you mean group them in design view, then take a look at the InSelection
property.

If you mean access them in a loop from VBA at runtime, then its up to you to
name them consistently, like:

Textbox1, Textbox2, Textbox3 etc.

Then you can do:

For i = 1 To 3
Debug.Print me.Controls(Textbox" & i).Name
Next
 
S

Stuart McCall

Debug.Print Forms!Form1!Text1.Controls(0)

Sorry, that line should read:

Debug.Print Forms!Form1!Text1.Controls(0).Name
 
V

Viarum via AccessMonster.com

Thank you, I did'nt realize that controls have also collections appended to
them.
About the groups: your suggestion of accessing the controls in a loop is an
alternative. Controls you want to be grouped can have e.g. a similar name and
filtered out. But what I was looking for is, using the groups defined in
design mode as a sort of flexible optiongroups which can contain any other
control. You will answer me that subforms can do the trick, but this is only
true for rectangular areas, not to speak about th impact on existing forms
and their code.
 

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