List Box Forms

N

Nimish

I havea form that I have created with two list boxes. The macros
launches a filter. How do I create a property in the list box that
would allow a user to "deselect" the list box. Right now, once the
user clicks in the box, a name is highlighted and the only option is
the select another name. You can't click on a name again and deselect
it.

My code is:

Private Sub CommandButton1_Click()
vEmpSups = frmSupervisors.lstEmpSups.Value
vRoutesups = frmSupervisors.LstRouteSups.Value

Sheets("DispatchSheet").Select
Selection.AutoFilter
Selection.AutoFilter Field:=1, Criteria1:=vEmpSups
Selection.AutoFilter Field:=2, Criteria1:=vRoutesups

End Sub
 
H

Harald Staff

Hi

Something like

Private Sub BtnDeselect_Click()
frmSupervisors.lstEmpSups.Listindex = -1
End Sub

HTH. Best wishes Harald
 
N

Nimish

Where would I place that sub....in my forms macro? How does it fit in
with the coding?

Thanks
 
H

Harald Staff

That would depend on how and when you want this deselection to happen. But
if it's a "deselect" commandbutton on the form, then it goes inside that
one's click event.

Your provided code is a little confusing. If Private Sub
CommandButton1_Click() is inside ther form's own module then you should
address its controls with Me instead of the form's name. Not

vEmpSups = frmSupervisors.lstEmpSups.Value
vRoutesups = frmSupervisors.LstRouteSups.Value

but

vEmpSups = Me.lstEmpSups.Value
vRoutesups = Me.LstRouteSups.Value

Same goes for the code I wrote you.

HTH. Best wishes Harald
 
Top