If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Problem accessing the LIST property of a listbox
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 |
#2
|
|||
|
|||
Problem accessing the LIST property of a listbox
Answered in Forms newsgroup.
-- Brendan Reynolds Access MVP "John T Ingato" wrote in message ... 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 |
Thread Tools | |
Display Modes | |
|
|