Problem accessing the LIST property of a listbox

  • Thread starter Thread starter John T Ingato
  • Start date Start date
J

John T Ingato

I had encountered tis problem a while back and do not remember if I ever
solved it.

I have created a form with checkboxes. Once a checkbox is clicked, a click
event procedure is called that adds a string to a list box. Very simple.
If the checkBox is checked, add the string. If it is unchecked, remove the
string. i would like to write a sub that searches through all the items in
the listbox, find a match to a string and returns the index, so I can call
"ListBox.RemoveItem(index)"

Here is the code I was thinking would work. Help says that I CAN use the
"List" property of the listbox, e.g. Mystring = MyListBox.list(4), but the
compiler says "List" is NOT a valid property. Why? Anyone?
Can someone tell me the best way to do this?
My final goal is to take each item that is check and create a query string
out of it, then create a report of those items.

Private Sub The407_01CheckBox_Click()

Call BoxClicked(The407_01CheckBox, "#2 Tape")

End Sub

Private Sub The405_01CheckBox_Click()

Call BoxClicked(The405_01CheckBox, "#1 Stains")

End Sub

Private Sub BoxClicked(objCheckBox As CheckBox, ListData As String)

Dim IndexInList As Integer, objLB As ListBox

Set objLB = Me.MyList

If objCheckBox.Value = True Then
MyList.AddItem (ListData)
Else
Dim LB As ListBox
Call RemoveFromList(objLB, ListData)
End If

End Sub

Private Function RemoveFromList(ByRef LB As ListBox, TestString As String)
as integer
Dim i as single

for i = 0 to MyListBox.Listcount - 1
if LB.list(i) = TestString then
LB.RemoveItem(i)
exit for
end if
next i

End Sub
 

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

Back
Top