List Box Selection Code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm merely trying to hide some controls with the "CP" Tag if the selection
"Critical Period" is chosen in the list box.

Code isn't working. Can anyone spot the problem?

Private Sub lstProd_Type_AfterUpdate()

Dim C As Control

Select Case [lstProd_Type]
Case "Critical Period"
For Each C In Me.Controls
If C.Tag = "CP" Then
C.Visible = True
End If
Next
Case Else
For Each C In Me.Controls
If C.Tag = "CP" Then
C.Visible = False
End If
Next
End Select
 
Have you checked the Value of lstProd_Type to verify what it actually is?
The Value of the listbox comes from the Bound Column. If you have more than
one column, the Bound Column may not be a visible column. If that is the
case, you have two options.

1) Test for the value that is being returned (i.e. the value of the Bound
Column for the selected row).

2) Specify which column to read a value from by using the listbox's Column
property.

Also, make sure the listbox is not set for Simple or Extended Multi Select
(Other tab). If it is set for Multi Select, it doesn't have a value.
Instead, you have to loop through the SelectedItems property to get the
value from each selected row.
 
Try the following:

Private Sub lstProd_Type_AfterUpdate()

Dim C As Control

Select Case [lstProd_Type]
Case "Critical Period"
For Each C In Me.Controls
If C.Tag = "CP" Then
C.Visible = False
else
C.Visible = False
End If
Next
Case Else
End Select
 
Back
Top