Unselect values from listbox(es)

I use a several (unbound) listboxes on a form (for filtering records).

I'd like to include a "Clear Filter" cmdButton that will UNSELECT all select values (not rowsource) in the listboxes.   Pls keep in mind that my listboxes are Multi-Select = "Expanded".

The code "Me.lstCTM.RowSource = Null" did not work.

EEH
ExpExchHelpAsked:
Who is Participating?
 
Rey Obrero (Capricorn1)Connect With a Mentor Commented:
try

sub ClearListBox()
dim j, ctl as control

for each ctl in me.controls
  if ctl.controltype=aclistbox then
       with me(ctl.name)
               for each j in .itemsselected
                     .selected(j)=false
                next
        end with
  end if
next
end sub
0
 
Rey Obrero (Capricorn1)Commented:

sub ClearListBox()
dim j

with me.listboxName
   for each j in .itemsselected
          .selected(j)=false
   next
end with
end sub
0
 
ExpExchHelpAuthor Commented:
Capricorn,

thanks, that works great.   Is there a way to unselect several listboxes within one statement?   Or do I need to create a loop for each listbox?

EEH
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
ExpExchHelpAuthor Commented:
That works perfect!!!

Thanks so much,
EEH
0
 
PissingSkunkCommented:
What about just putting nothing in the control:

Me.lstCTM = ""

PS
0
 
Rey Obrero (Capricorn1)Commented:
PissingSkunk,
did you ever tried that before posting?
0
 
PissingSkunkCommented:
Yes, but you obviously not before commenting....
Works for me in A97, A200, A2002 and A2007.
Give it a try and report the results :-)

PS
0
 
Rey Obrero (Capricorn1)Commented:
how do you think that the code you posted will *unselect* selected items from a list box?
0
 
PissingSkunkCommented:
How do you think that it doesn't ?

PS
0
 
PissingSkunkCommented:
Ping...

Took the time to test ?

PS
0
 
PissingSkunkCommented:
And ?

PS
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.