Create a control with Code

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

Guest

Thanks for taking the time to read my question.

I have a form that I want to filter. I want an option box to control the
filter.

When the form opens I would like to build the option box and have as many
options as there are unique records to filter on.

Eg: If the data had Oranges and Apples, I'd like my form to open, with an
option box that has two choices, Oranges and Apples. Default could be
Oranges, but I could click on the Apples option, and then the form is
filtered for Apples. Now I close the form, add Grapes to the data, and open
the form again. I'd lke the form to have Oranges, Apples and Grapes as my
options now.

I can use a recordset to return the unique values, but how do I make an
option box with code everytime the form opens?

Thanks,

Brad
 
Brad said:
Thanks for taking the time to read my question.

I have a form that I want to filter. I want an option box to control
the filter.

When the form opens I would like to build the option box and have as
many options as there are unique records to filter on.

Eg: If the data had Oranges and Apples, I'd like my form to open,
with an option box that has two choices, Oranges and Apples. Default
could be Oranges, but I could click on the Apples option, and then
the form is filtered for Apples. Now I close the form, add Grapes to
the data, and open the form again. I'd lke the form to have Oranges,
Apples and Grapes as my options now.

I can use a recordset to return the unique values, but how do I make
an option box with code everytime the form opens?

Thanks,

Brad

Access is not really good at creating controls on-the-fly and you eventually
hit a lifetime limit on the number of controls a form is allowed to have.

This sounds like overkill anyway. Why not just use a ListBox or ComboBox?
It will automatically display however many unique entries you have with no
extra work at all.
 
Thanks for the reply Rick,

I know... it's WAY overkill. I just wanted to learn how to build a form
programatically.

How do you name the new controls?

Brad
 
Brad said:
Thanks for the reply Rick,

I know... it's WAY overkill. I just wanted to learn how to build a
form programatically.

How do you name the new controls?

I have no idea as I have never programmatically created a control. I would
assume one adds a control to the controls collection using an "add" or "create"
method exposed by the collection object.
 
Back
Top