Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"De-Selecting" Items in a LISTBOX 2

Status
Not open for further replies.

ZaZa

Technical User
Sep 5, 2001
85
US
Hi everyone,

I have a dailogue form with a very long multiple-select list box.User selects several criteria from the list box and then clicks on a command button on the form to run a report based on his selections. This bit works fine( thanks to some previous help from this site).

Sometimes the user may select some criteria( say,for example 2 criteria) and then change his mind and forget to de-select the criteria he chose. Next few minutes he wants want to run another report and clicks on 3 new critera. Because he didn't clear( I use the term "de-select") his first 2 criteria, the report is run based on 5 criteria instead of just his 3 new criteria.

I want to add a command button called ClearSelections to "de-select" all previous selections . So the user can click that button before choosing a new set of selections. That way he is sure that the report is based only on his most recent selections.

I have been messing arounbd with the following code on the Onclick events for the ClearSelections button
:
-----------------------------------
Dim cntl As Control
Dim lngCounter As Long
Dim varItem As Variant

Set cntl = Me.MyListBox
lngCounter = cntl.ItemsSelected.Count - 1

For Each varItem In cntl.ItemsSelected
cntl.Selected(lngCounter) = False

lngCounter = lngCounter - 1
Next varItem

MsgBox " Selections have been CLEARED"
--------------------------------------

PROBLEM:
When I hit the ClearSelection button, only some of the items get cleared. Sometimes none of the items get clreared.

QUESTION:
a)I am a very new vba user so maybe I wrote it wrong. Did I?

b)Also should I say something like FIND all the records in the list box Where MyListBox.Selcted = True ...blah blah .Then say MyListBox.Selected= False....Blah blah blah?
If so then please help becasue I can't figure out how to write that one either.

Thanks a lot in advance,
ZaZa
 
Hi!

You say you are using the selected items in another routine, why not just clear the selections as you find and use them? Since you are getting all the information there all right you should be able to clear them all there as well.

hth
Jeff Bridgham
 
Try this code that was kindly provided by Joe Miller previously
Dim i As Integer

For i = 0 To (ListFilter.ListCount - 1)
ListFilter.Selected(i) = False
Next i

listfilter was the name of my listbox.
Very simple very effective.
 
Hi JaneInMA and Jeff

Jeff,

Thanks for your suggestion. it is a very good idea. But what coulds happen also is that a user could begin selectinng some criteria from the list, get disrtracted and stop BEFORE hitting the PrintReport button and does not close the form, goes for cofee and comes back to the form a while later and starts selecting a different set of criteria.( I know becasue this ghappened to me last night). So the report generated ends up with the first and second set of criteria.

So I have a button called ClearSelection for scatterbrained perople ( like Moi) who might be doing dozens and things at one time.I hope you get my drift.

JaneInMA,
Thanks a lot for that code. it is working well


Guys thank you. Two heads are definately better than one becasue I have also incorporated Jeff's idea into the PrintReport button so it also clear the selections after opening the report.

Cheers,
ZAZA

Thanks again and keep up the good work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top