Unbound Combo Box

G

Guest

I have 10 unbound combo boxes on a form. Users will use these to selected
the desired attributes for display and printing. The problem I'm having is
determining if the combo box has a value.

I'm looking for an automated way of checking them, rather than 10
IF..THEN..ELSE codes. All combo boxes have similar names
Form![myform![combo1], form![myform]![combo2],etc. Can I set up a FOR LOOP
or something to step through them easily and assign a variable the values?
 
R

Rick Brandt

Justin said:
I have 10 unbound combo boxes on a form. Users will use these to selected
the desired attributes for display and printing. The problem I'm having is
determining if the combo box has a value.

I'm looking for an automated way of checking them, rather than 10
IF..THEN..ELSE codes. All combo boxes have similar names
Form![myform![combo1], form![myform]![combo2],etc. Can I set up a FOR LOOP
or something to step through them easily and assign a variable the values?

You can easily do this in a loop for referencing the ComboBox names...

For i = 1 to 10
If Not IsNull(Me.Controls("combo" & i)) Then
...
Next i

....but, i have no idea how you would automatically refer to the 10 different
variables. If there is a way to refer to a variable name using a string I am
not aware of it.
 
B

Bill Edwards

In line
Rick Brandt said:
Justin said:
I have 10 unbound combo boxes on a form. Users will use these to selected
the desired attributes for display and printing. The problem I'm having
is
determining if the combo box has a value.

I'm looking for an automated way of checking them, rather than 10
IF..THEN..ELSE codes. All combo boxes have similar names
Form![myform![combo1], form![myform]![combo2],etc. Can I set up a FOR
LOOP
or something to step through them easily and assign a variable the
values?

You can easily do this in a loop for referencing the ComboBox names...

For i = 1 to 10
If Not IsNull(Me.Controls("combo" & i)) Then
...
Next i

...but, i have no idea how you would automatically refer to the 10
different variables. If there is a way to refer to a variable name using
a string I am not aware of it.

Perhaps use an array.
Could use a two dimensional array: column 1 = the name of the field in the
report to filter, column 2= the value retrieved from the corresponding combo
box.

 
G

Guest

That works great. Thanks.

Rick Brandt said:
Justin said:
I have 10 unbound combo boxes on a form. Users will use these to selected
the desired attributes for display and printing. The problem I'm having is
determining if the combo box has a value.

I'm looking for an automated way of checking them, rather than 10
IF..THEN..ELSE codes. All combo boxes have similar names
Form![myform![combo1], form![myform]![combo2],etc. Can I set up a FOR LOOP
or something to step through them easily and assign a variable the values?

You can easily do this in a loop for referencing the ComboBox names...

For i = 1 to 10
If Not IsNull(Me.Controls("combo" & i)) Then
...
Next i

....but, i have no idea how you would automatically refer to the 10 different
variables. If there is a way to refer to a variable name using a string I am
not aware of it.
 

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