Filter Listbox

  • Thread starter Brian Blakistone
  • Start date
B

Brian Blakistone

Hi,

I have a listbox that I would like to be able to filter
based on input into a text box. Is there an easy way
to query or filter the listbox values? I was thinking
of storing them to an array, clearing the listbox and
then adding back those values that match, but is there
an easier/faster way?

Thanks.
Brian
 
W

Word Heretic

G'day (e-mail address removed) (Brian Blakistone),

Yes there is - it is well within MVP capabilities - let's see if they
tray and attempt it. If not, I'll help.

BOUNCE

Steve Hudson - Word Heretic
Want a hyperlinked index? S/W R&D? See WordHeretic.com

steve from wordheretic.com (Email replies require payment)


Brian Blakistone reckoned:
 
P

Peter Hewett

Hi Brian

The code that populates the listbox is simple. It's the bit in the middle you
have not elaborated on, namely, what sort of fitering do you want to do. If
the match criteria is tricky that's where the complexity can creep in.

So please provide a sample of the list data and how you want it filtered.

Cheers - Peter


(e-mail address removed) (Brian Blakistone) wrote in @news.individual.net:
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

The way I do this sort of thing is to have the entries for the combobox in
the first column of a table in a document that I use as the source, with one
entry per row, and the entries for the listbox that correspond to each item
in the combobox as individual paragraphs in the cell in the second column of
the table on the same row. Then I use code such as the following in the
change event of the combobox

Private Sub CmbCompany_Change()
' This code populates the SalesRep combo with the relevant sales reps
based on the company
' that has been selected.
CmbSalesRep.Clear
Dim sourcedoc As Document, i As Long, myitem As Range
' Modify the path in the following line so that it matches where you saved
Suppliers.doc
Set sourcedoc = Documents.Open(FileName:="d:\worddocs\Suppliers.doc")
For i = 1 To sourcedoc.Tables(1).Cell(CmbCompany.ListIndex + 2,
2).Range.Paragraphs.Count
Set myitem = sourcedoc.Tables(1).Cell(CmbCompany.ListIndex + 2,
2).Range.Paragraphs(i).Range
myitem.End = myitem.End - 1
CmbSalesRep.ADDITEM myitem.Text
Next i
sourcedoc.Close SaveChanges:=wdDoNotSaveChanges
End Sub

The above is from a userform in a template where the user selects a company
from a combobox and then another combobox is populated with the sales
representatives for that company. You can use this technique to populate a
listbox in the same way.

Whether it is any better than the way that you propose, I don't know.
--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 

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

Top