Check if an item is in a listbox

  • Thread starter Thread starter Tony_VBACoder
  • Start date Start date
T

Tony_VBACoder

With Access 2002, is there a fast way to determine if a
value exists in a listbox? I have the following function
that will accomplish this, but I didn't know if ACC2002
has come up with it's own Function:

Public Function bIsItemInListBox(sValue As String,
objListBox As ListBox) As Boolean
Dim iIndex As Integer

With Me
For iIndex = 0 To objListBox.ListCount - 1
If sValue = objListBox.ItemData(iIndex) Then
bIsItemInListBox = True
Exit Function
End If
Next
End With

End Function
 
Tony,

What is the source of your listbox, a table, query, or list. If it is a
list you typed in, put the list in a table and use a table. Then all you
have to do is a DLOOKUP() of the table or query to determine whether the
value exists.

HTH
Dale
 
The RowSource of my list box is sometimes a Query and
other times a list of items that were added using
the .AddItem method. The list can change depending on a
value selected in a combo box on my form or if the user
manually adds items to it. So I really need to focus just
on those items that are in the list box, which is why I
was wondering if Acc2002 has come up with it's own
function that determines if a value is in the list box.


My function works great, but if Acc2002 has it's own
function that I can use instead, I'd go that route.
 
Not that I'm aware of.

I know VB programmers have to use the .addItem method, but if you are using
Access, the way to go is to use tables and queries to populate this lists.
I was not aware that the Access listbox had an AddItem method. What version
are you using?

Dale
 
Back
Top