Filter on a lisbox entry

P

Paul Cram

I have a form which shows contacts. There is a listbox which has the type of
contact as each contact may be in more than 1 category. I want to be able to
hide certain cantacts when the form opens and therefore was looking to filter
on the list box. The list box has 2 columns and the first is an ID column. In
the form open event I have the following code:
DoCmd.ApplyFilter "Me.lstCategory <> 2"
This does not apply the filter. Any ideas why not.

Regards
Paul
 
K

Klatuu

Is lstCategory a Multi Select list box? If so, that will not work. A Multi
Select list box will not return a value. You have to use the ItemsSelected
collection property of the list box to determine which items have been
selected. VBA Help has a good example. Search for ItemsSelected and look at
the example.
 
P

Paul Cram

It is not a multi select box but is unbound and populated by by a routine
that fills the details into the rowsource.

Regards
Paul
 
K

Klatuu

Paul,
I misread your post yesterday. The ApplyFilter method does not do what you
are wanting to do. It only applies to forms, reports, and tables. In
addition, the Open event of the form would be too soon. The earliest you
could do this would be in the Load event. Even then, so selection has been
made in the combo.

If you can describe what your objective is, perhaps we can offer some
suggestions.
 
Top