Hide Controls based on the value of a Text

G

Guest

I have a form that contains one combo box and 25 text boxes.

1. The combo box autopopulates the boxes.

2. One particular text box is called Area, which pertains to a particular
department.

3. The other 24 text boxes pertain to a training module.

What is I want to do is implement some VB code that will hide some of the 24
text boxes(during runtime) based on the value in the text box called Area.

N.B. - Remember that the combo box auto-populates the text boxes.
 
G

Guest

Try setting the visibility of the text boxes on the after update event of the
combo

For example, set the text box to be visible only if the Area = "Value"

Me.[TextBox1Name].Visible = (Me.Area = "Value")
Me.[TextBox2Name].Visible = (Me.Area = "Value")
Me.[TextBox3Name].Visible = (Me.Area = "Value")

If you navigate between records, you'll need to set this code also on the
OnCurrent event of the form
 
G

Guest

If you don't mind me asking, what is the significance of setting the same
code on the OnCurrent Event of the form. I just want to know the logic
behind your idea for
For Future reference.


Ofer Cohen said:
Try setting the visibility of the text boxes on the after update event of the
combo

For example, set the text box to be visible only if the Area = "Value"

Me.[TextBox1Name].Visible = (Me.Area = "Value")
Me.[TextBox2Name].Visible = (Me.Area = "Value")
Me.[TextBox3Name].Visible = (Me.Area = "Value")

If you navigate between records, you'll need to set this code also on the
OnCurrent event of the form
--
Good Luck
BS"D


Olu Solaru said:
I have a form that contains one combo box and 25 text boxes.

1. The combo box autopopulates the boxes.

2. One particular text box is called Area, which pertains to a particular
department.

3. The other 24 text boxes pertain to a training module.

What is I want to do is implement some VB code that will hide some of the 24
text boxes(during runtime) based on the value in the text box called Area.

N.B. - Remember that the combo box auto-populates the text boxes.
 
G

Guest

If you moving between records and the value in the Area text box is already
set then the event that will be activate is the OnCurrent event, so you can
use it to hide or show the other text box.

The other option is using the AfterUpdate event of the combo, when the Area
will be set to set the visibility of the text boxes.

There is no need to write the code twice, you can set the OnCurrent event to
set the fields, and call the OnCurrent sub from the After Update event of the
combo

--
Good Luck
BS"D


Olu Solaru said:
If you don't mind me asking, what is the significance of setting the same
code on the OnCurrent Event of the form. I just want to know the logic
behind your idea for
For Future reference.


Ofer Cohen said:
Try setting the visibility of the text boxes on the after update event of the
combo

For example, set the text box to be visible only if the Area = "Value"

Me.[TextBox1Name].Visible = (Me.Area = "Value")
Me.[TextBox2Name].Visible = (Me.Area = "Value")
Me.[TextBox3Name].Visible = (Me.Area = "Value")

If you navigate between records, you'll need to set this code also on the
OnCurrent event of the form
--
Good Luck
BS"D


Olu Solaru said:
I have a form that contains one combo box and 25 text boxes.

1. The combo box autopopulates the boxes.

2. One particular text box is called Area, which pertains to a particular
department.

3. The other 24 text boxes pertain to a training module.

What is I want to do is implement some VB code that will hide some of the 24
text boxes(during runtime) based on the value in the text box called Area.

N.B. - Remember that the combo box auto-populates the text boxes.
 
B

BruceM

Won't the text boxes need to be set back to Visible (or not visible) in the
Current Event before testing Me.Area? In other words, if they are not
visible by default, and if the code for one record sets five text boxes to
visible, won't they remain visible unless explicitly rendered otherwise?
I was starting to experiment with this, and I believe Select Case would be a
more efficient approach. The real complication, though, is that setting the
text boxes to visible or not depending on the value in a text box could be
unwieldy if there are a lot of variations. If ten different values in the
text box mean ten different combinations of visible and invisible text boxes
elsewhere on the form, that's quite a few lines of code.
I have often read your good advice in this forum, and I don't want to
intrude on your reply now, but I was working on some thoughts when I noted
your reply, so I decided to respond in this way rather than heading off in
another direction.

Ofer Cohen said:
Try setting the visibility of the text boxes on the after update event of
the
combo

For example, set the text box to be visible only if the Area = "Value"

Me.[TextBox1Name].Visible = (Me.Area = "Value")
Me.[TextBox2Name].Visible = (Me.Area = "Value")
Me.[TextBox3Name].Visible = (Me.Area = "Value")

If you navigate between records, you'll need to set this code also on the
OnCurrent event of the form
--
Good Luck
BS"D


Olu Solaru said:
I have a form that contains one combo box and 25 text boxes.

1. The combo box autopopulates the boxes.

2. One particular text box is called Area, which pertains to a
particular
department.

3. The other 24 text boxes pertain to a training module.

What is I want to do is implement some VB code that will hide some of the
24
text boxes(during runtime) based on the value in the text box called
Area.

N.B. - Remember that the combo box auto-populates the text boxes.
 

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