Link to home
Start Free TrialLog in
Avatar of rltomalin
rltomalinFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Grouping form fields together

I have a form where I wish to "expose" certain fields dependant on the value entered in a combo box.
I have the code working fine, but there are several fields for each option and I wondered if there was any way to group fields together (with a name designation) so that the code can sort of say:

If cboBox = "Value" Then
FieldGroup.BackColor = -2147483633
End If

or something like that.
Just thinking about readability of the code and ease of maintenance.

Regards

Richard
SOLUTION
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rltomalin

ASKER

Hello Guys
Wow - that was quick.  I have two solutions here that I will checkout and select which I would prefer.
Thanks for your excellent (as always) support.

Regards

Richard
Another way to do this with logically grouped controls is to define the group with a consistent naming convention using sequential numbers, and loop through the controls based on name.

For example, name a group of textboxes txtThing01, txtThing02, txtThing03 ... etc, and use code like this:

Dim I as integer

For  I = 1 to 10 
             If me.cboBox = "Value" then
                  Me.Controls("txtThing" & Format(I,"00")).backcolor =  -2147483633
             else
                  Me.Controls("txtThing" & Format(I,"00")).backcolor =  something else
             end if
Next

Open in new window