Dynamic Option Group

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to make a form that automatically fills in an option group with
the correct number of radio buttons, based on table entries.

For instance, when the form opens, it reads the table "Buildings" and
creates a button and a label for each entry it finds.

I know that this can be done in VB6... I just don't know if I can do it in
Access VBA. I looked under the properties for the options boxes, and I can't
find anything that would seem to fit. So I don't even know if this is
possible. Any ideas?

Thanks!

Nick
 
Look in VB Help for the CreateControl method. Be aware this only works if
the form is open in Design mode.
 
One common technique is (in design mode) to create the option group with
a sufficient number of option buttons, with their Visible property set
to False.

Then when you load the form, unhide the necessary number of buttons and
set their Captions to the relevant values from your table. If you want
to get fancy, you can adjust the positions of the buttons to make the
form look neater.

Doing it this way avoids the complication of opening the form in Design
view under program control. More important, creating controls on the fly
as part of routine operations means you're likely to get bitten by the
"lifetime" limit of 754 controls on a form.

Or if you want to keep things simple, replace the option group with a
combobox or listbox. That's by far the simplest way to build a UI for
the user to select one item from a set choices that aren't known at
design time.
 
Back
Top