I am using Access 2000. I am working on Visual Basic code behind my Access forms. I am fairly new to VBA....
I am trying to figure out a good way to check to see if an item is in a listbox control. In regular Visual Basic, the listbox control uses an Items object which has a Contains() method that is very easy to use to check if an item is in the listbox.
Here is an example (in Visual Basic) of what I am trying to do:
Dim x As Integer
Dim testValue As String = "Test"
If Me.ListBox1.Items.Contains(testValue) Then
' There is at least one in the listbox
' Now go find them
For x = 0 To Me.ListBox1.Items.Count - 1
If Me.ListBox1.Items.Item(x) = testValue Then
MessageBox.Show("Found it at Index: " & x)
End If
Next x
End If
The VBA listbox object does not seem to support this.
I imagine that I am not the first person to try to find an item in a listbox and was wondering if anyone has any recommendations on how best to go about this.
Thanks
Bill
19-11-2007 at 02:18 PM
|
stickleprojects Level: Moderator Registered: 09-09-2002 Posts: 937
Re: How do I find items in a VBA Listbox control
Hi Bill,
Skip the contains test and continue with the rest. It's the only way, I'm afraid.
____________________________
Build it better, faster, quicker, easier.. then fix it (non-offical MS mission statement)