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
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"
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