A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Problem accessing the LIST property of a listbox



 
 
Thread Tools Display Modes
  #1  
Old November 27th, 2006, 01:56 AM posted to microsoft.public.access.queries
John T Ingato
external usenet poster
 
Posts: 52
Default 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  
Old November 27th, 2006, 09:50 AM posted to microsoft.public.access.queries
Brendan Reynolds
external usenet poster
 
Posts: 1,241
Default 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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 12:11 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.