Grouped Controls In VBA?

V

victorcamp

The feature to group controls has been available in Access for quite a while
(Format->Group). Is there any way to refer to one of these groups via VBA?
I've searched the Object Model without luck.

Here's the reason:

I use the Form_Resize() event to dynamically move things around as the user
adjusts the form size. In particular, growing and shrinking an embedded
subform. It all works slick! However, there's an option group beneath the
subform that has to be moved along with the growing or shrinking subform.

As anyone who's ever tried moving option groups with code knows, moving the
group does not move its options, which have to be moved separately. If you
move the group, it simply stretches the frame to cover its new location and
the original location of the options. Then you move the options. Then you
resize the frame.

What I'd like to do is group the option group, along with its option buttons
and labels, then just move this group as one, like you can if you were
actually in Design View. I would have expected something like,
Form(0).Groups(2).Top = ... But no such luck.

Has anyone found a way to do this? The applications I'm working with are in
Access 2003 and Access 2000.
 
M

Matt Richardson

The feature to group controls has been available in Access for quite a while
(Format->Group). Is there any way to refer to one of these groups via VBA?
I've searched the Object Model without luck.

Here's the reason:

I use the Form_Resize() event to dynamically move things around as the user
adjusts the form size. In particular, growing and shrinking an embedded
subform. It all works slick! However, there's an option group beneath the
subform that has to be moved along with the growing or shrinking subform.

As anyone who's ever tried moving option groups with code knows, moving the
group does not move its options, which have to be moved separately. If you
move the group, it simply stretches the frame to cover its new location and
the original location of the options. Then you move the options. Then you
resize the frame.

What I'd like to do is group the option group, along with its option buttons
and labels, then just move this group as one, like you can if you were
actually in Design View. I would have expected something like,
Form(0).Groups(2).Top = ...  But no such luck.

Has anyone found a way to do this?  The applications I'm working with are in
Access 2003 and Access 2000.

Unfortunately there isn't an object that controls a group. There's a
method which uses Tags below which could be useful:-

http://p2p.wrox.com/excel-vba/15901-arrays-controls-vba-excel.html

HTH
http://2toria.com
http://teachr.blogspot.com
 
V

victorcamp

Thanks for the suggestion. I am obsessive with the naming of objects, so I
have no difficulty with loops using a syntax like, .Controls("opgMyGroup" &
CStr(lngX)).Top =... . Ultimately, I opted for first enlarging the frame to
encompass its old and new position, then moving the option buttons and
labels, then closing the frame around the new position.
 
D

David W. Fenton

Thanks for the suggestion. I am obsessive with the naming of
objects, so I have no difficulty with loops using a syntax like,
.Controls("opgMyGroup" & CStr(lngX)).Top =...

If you're doing that more than once, you'd be well-advised to create
a custom collection holding references to the subset of controls,
and walk that custom collection instead of the entire controls
collection. The first time I tried this, I was stunned that the
result was noticeably faster to the end user -- it wasn't just one
of those cases of shaving off milliseconds that an end user would
never notice.
 

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