Group:  Microsoft Access ยป microsoft.public.access.formscoding
Thread: Associated labels and groups

Geek News

Associated labels and groups
"Viarum" <u48365[ at ]uwe> 12/23/2008 5:51:03 PM
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!

Re: Associated labels and groups
"Stuart McCall" <smccall[ at ]myunrealbox.com> 12/23/2008 6:04:21 PM
Answers inline:

"Viarum" <u48365[ at ]uwe> wrote in message news:8f1a13c769b0f[ at ]uwe...
[Quoted Text]
> 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


Re: Associated labels and groups
"Stuart McCall" <smccall[ at ]myunrealbox.com> 12/23/2008 11:23:13 PM
Answers inline:

"Viarum" <u48365[ at ]uwe> wrote in message news:8f1a13c769b0f[ at ]uwe...
[Quoted Text]
> 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


Re: Associated labels and groups
"Stuart McCall" <smccall[ at ]myunrealbox.com> 12/23/2008 11:28:50 PM
[Quoted Text]
> Debug.Print Forms!Form1!Text1.Controls(0)

Sorry, that line should read:

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


Re: Associated labels and groups
"Viarum via AccessMonster.com" <u48365[ at ]uwe> 12/24/2008 8:23:37 AM
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.

Stuart McCall wrote:
[Quoted Text]
>> Debug.Print Forms!Form1!Text1.Controls(0)
>
>Sorry, that line should read:
>
>Debug.Print Forms!Form1!Text1.Controls(0).Name

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/200812/1

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net