Unhide/enable controls when certain value is chosen from listbox on form

MvP14

Registered User.
Local time
Today, 16:59
Joined
Apr 15, 2003
Messages
66
I have a couple of controls on a form that I wish to hide/disable. So far no problem. However, I want them to be unhidden or enable when a certain value is chosen in a listbox on that same form.

Any one any suggestions?

Thanks in advance!
 
You could put a "secret code" in the Tag property of the controls you want to enable/make visible and then loop through each control on the form, review its tag property and then enable/make visible accordingly.
 
Or on the on_click event of the list box have an IF statement:

IF YourListBox.Value = WhateverValue then
YourControl.Visible = True
YourControl.Enabled = True
Else
YourControl.Visible = False
YourControl.Enabled = False
END IF
 
Say, he had about 10 controls to become visible - what looks more manageable? The huge list or the quick loop?
 
Point taken.

Although if he only has a couple of controls, looping through the lot does seem a tad excessive....;) ;)
 
I'm sorry, but I'm really an amateur.

Do you mean, loop through all the controls after the value in the listbox is chosen?

Do you mean that looks a bit like this:

Dim ctl As Control
Dim strvalue As String
Dim strtag As String

strtag = "Enable"
strvalue = "References"

If Me.lstTables.Value = strvalue Then
For Each ctl In Me.Controls
If ctl.Tag = strtag Then
ctl.Enable = True
End If
End If

And is it sufficient that I add enable to the tag in the properties box of the relevant controls?

In case all the former is affirmative: where do I call the code? In the afer update?
 
Oops, looks like I missed some replies as I was trying to figure it out. There are six controls that have to be enabled/ become visible. Maybe I should just list them all.

I'll try it out and come back to you!
 
MattS said:
Or on the on_click event of the list box have an IF statement:

IF YourListBox.Value = WhateverValue then
YourControl.Visible = True
YourControl.Enabled = True
Else
YourControl.Visible = False
YourControl.Enabled = False
END IF
The code would have to go in the Form_Current event
In the onclick event would be
Form_Current
or
Call Form_Current
 
That's a great example, but for some reason, it doesn't work in my case. Well, that is to say, it works only once. When the value is chosen the controls appear, however, when after that I chose another value, they don't disappear. I guess, the code interferes with other code on the form.
 
Possibly - if you have other code in your Form_Current event then it may cause a problem.
 
I've messed around with it a bit more, and now it works! Thank you! It would have taken me days if I had had to do it all by myself.
 

Users who are viewing this thread

Back
Top Bottom