Select all or deselect all check box

pepperlc

New member
Local time
Today, 14:13
Joined
Jul 30, 2010
Messages
6
Not even sure where to look for this. I have a multi-select listbox that is used to filter a report. The listbox works great but I wanted to add a select all or deselect all feature to the window. Can someone tell me how to do it or were to look for information about it?

thanks
pepper
 
Incorrect code (was Air code) and so I tested and revised (see posts below for revised, corrected code).
 
Last edited:
You would stick that function in a standard module (don't name the module the same as the function).

Then you can use it for ANY listbox you have as long as it has multi-select set to either Simple or Extended.
 
Okay, I goofed a bit. Here's the better version which works (tested):
Code:
Function SelDeselAll(strForm As String, strCtl As String, blnSetOrUnset As Boolean)
Dim i As Integer
Do Until i = Forms(strForm).Controls(strCtl).ListCount
    Forms(strForm).Controls(strCtl).Selected(i) = blnSetOrUnset
    i = i + 1
Loop
End Function

Then call it like this:

SelDeselAll Me.Name, "listBoxNameHere", True
 
Using SOS’s code (and why not; it was already built :D ) there is a little demo attached.

No check box but (All) and (None) in the list.
 

Attachments

Thanks for the code and demo.

Sos: Does this work with a check box? And I'm guessing it just toggles everything one way or another through the entire list. Is that right? I would put this function in the checkbox click event?

ChrisO's code: I'm concerned that the (all) and (none) will be sent to my query when the user clicks "run report".
 
I usually have 3 a three button option group

Select All

Deselect All

Toggle


Select All:

Code:
For n = 1 to Me.Listbox.Listcount -1
    Me.Listbox.Selected(n) = True
Next


Deselect All

Code:
For n = 1 to Me.Listbox.Listcount -1
    Me.Listbox.Selected(n) = False
Next

Toggle:

Code:
For n = 1 to Me.Listbox.Listcount -1
    Me.Listbox.Selected = not Me.listbox.Selected(n)
Next


You can pu all three in a select case statement on the option group click event by examining the index value

Code:
Select Case Index
    Case 1 :Select All
    Case 2 :Deselect All
    Case 3: Toggle
End Select
 
so toggle are the user selected ones?

This seems like a simpler way to do it. Do I use any of the code the others suggested?

thanks
pepper
 
As the options suggest: If you have a list of 20 items to save the use clicking all 20 the Select all button selects them all for you. Conversely the Deselect does the reverse and clear all the selections. The toggle option reverses selected to not selected and not selected to selected. A bit obvious I would have thought.

So lets say you want to run a report all 7 items in your list followed by another report for all the rest. You would select the 7 items for the first report and then print it. Next you would hit the toggle option to reverse the selections and then click print again. No need to deselect and re select the remining items in the list.
 
Pepper.

I think you are going about this question the wrong way.

You now have three ways to do it: -
1. Use a check box; only two or three choices available.
2. Put the choices directly in the same list as the data; even though I did that I don’t particularly like it. You could have many options but those options would help to fill the list box and would be mutually exclusive.
3. Option Group. Best so far because you can have as many options as you may require without adding to the list box but those options too are mutually exclusive.

Further down the track you may need multiple options that are not mutually exclusive.
Example: filter by this OR that or filter by this AND that or filter by this XOR that and throw in a sort order based on one or many fields.

What I would suggest is to stop writing code for the moment and look at the users requirements.
Once you have the end requirement it can be coded, if it is logical.

Your users will not care how it is coded; all they should want is the functionality in an easy to use manner.

So, ascertain the requirement, make it easy to use and then code it.
 
This looks really useful, but I can't seem to get it to work (due to my inexperience).

I'd be grateful for some basic advice as to how to use it to select/deselect all tickboxes in a continuous form.

Here is what DOESN'T work (how do I correct it?)

Private Sub SelectDeselectAll_Click()
SelDeselAll Me.NameOfMyForm, "NameOfCheckBox", True
End Sub

Thanks in advance
 
This looks really useful, but I can't seem to get it to work (due to my inexperience).

I'd be grateful for some basic advice as to how to use it to select/deselect all tickboxes in a continuous form.

Here is what DOESN'T work (how do I correct it?)

Private Sub SelectDeselectAll_Click()
SelDeselAll Me.NameOfMyForm, "NameOfCheckBox", True
End Sub

Thanks in advance
Could you create a new thread and mention what the Multiselect property is set to.
 
Can you tell me how to find the Multiselect property for a tick boxes in continuous forms? I can't seem to find one so can't say what it is set to. Then I can start a new thread.

Thanks
 
Can you tell me how to find the Multiselect property for a tick boxes in continuous forms? I can't seem to find one so can't say what it is set to. Then I can start a new thread.
There isn't one and your situation doesn't equate the same to the original thread. They were using listboxes on a single form. Selecting all checkboxes in a continuous form is completely different.
 

Users who are viewing this thread

Back
Top Bottom