By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,708 Members | 950 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,708 IT Pros & Developers. It's quick & easy.

Changing the visibility of multiple objects on a form

P: 6

I am using Access 2003 and I have a form with 120 textboxes in a grid layout. Depending on a selection made in a combo box, I want to change the visibility of certain textboxes in the grid. This is easy enough to do as a one-by-one basis but due to the number of textboxes I need to change I am wondering if there is a way I can make it hide a group of these boxes all at once?

For example, I group textboxes 1-11 and 30-40 as GroupA and group 12-20 and 80-100 as groupB, 1-11 and 80-100 as Group C and so on. Depending on the combo box I would just have my code says GroupA.visible = false, or something like that.

I don't believe I can use an option group as the same textboxes can be used by multiple combo lists results.

Is this possible of will I have to do a piece of code per textbox?

My other thought is of having a table with a true or false value for each textbox, either one table per combo selection (so each text box is a seperate record), or the one table which has each textbox as a field value per combo record. unfortunately this is a bit beyond my ability, I wouldn't know where to start coding to read through the data, I am guessing I will need loops?

Aug 27 '08 #1
Share this Question
Share on Google+
3 Replies

Expert 2.5K+
P: 2,653

First of all 120 textboxes mean that your database probably not normalized.
I suggest you to read Database Normalization and Table structures article.

If you still want to proceed with you current tables configuration then your 120 textboxes should be recognizable using one of the possible methods:
  • TextBox name should be based on some rule like txbHideMe1, txbHideMe2, txbHideMe3 ... txbHideMe120 or TextBox name may be recognizable by a constant substring.
  • You may use TextBox.Tag property to sign TextBox as a subject to switch it visibility.

Having done this, you could change TextBoxes property in loop either generating names or iterating all form controls to find those having appropriate name or Tag property value.

Expand|Select|Wrap|Line Numbers
  1. For i=1 to 120
  2.     Me.Controls("txbHideMe" & i).Visible = False
  3. Next i
Expand|Select|Wrap|Line Numbers
  1. For Each c in Me.Controls
  2.     if Instr(1, c.Name, "HideMe") <> 0 Then c.Visible = False
  3. Next
Expand|Select|Wrap|Line Numbers
  1. On Error Resume Next
  2. For Each c in Me.Controls
  3.     if c.Tag="HideMe" Then c.Visible = False
  4. Next
  5. On Error Goto 0
Aug 27 '08 #2

P: 6
Thanks mate, that worked.
Aug 28 '08 #3

Expert 2.5K+
P: 2,653
You are welcome.

Best regards,
Aug 28 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.