?
Solved

List: Multiple Select without Control Key and counter of selected items

Posted on 2006-03-25
13
Medium Priority
?
500 Views
Last Modified: 2012-06-21
Can I select multiple lines in list field without holding control key?

I also need reset button and if possible (not that important but would be nice) counter of selected items
0
Comment
Question by:IlijaK
  • 5
  • 4
  • 4
13 Comments
 
LVL 93

Assisted Solution

by:Patrick Matthews
Patrick Matthews earned 200 total points
ID: 16291623
Hi IlijaK,

> Can I select multiple lines in list field without holding control key?

If MultiSelect = Extended...
Well, you could hold down the Shift key, but that would select all the items between "point A" and "point B", rather
than the Ctrl key allowing you to pick and choose individual items.  Other than that, yes, I think you are stuck with
Ctrl.

If MultiSelect = Simple
Items are selected by clicking on them or with the Space bar

> I also need reset button

Me!ListBoxName.Requery

> and if possible (not that important but would be nice) counter of selected items

Put an unbound textbox on your form, with controlsource of
=SelectedInListbox("NameOfForm", "NameOfListbox")

Add this code to a regular (NOT form or report) module:

Function SelectedInListBox(FormName As String, LbName As String)

    SelectedInListBox = Forms(FormName)!Controls(LbName).ItemsSelected.Count

End Function

Will work in Access 2002 and 2003; not sure about earlier versions...

Regards,

Patrick
0
 

Author Comment

by:IlijaK
ID: 16292496
Patrich, thank you for the quick reply:

If MultiSelect = Simple works great! Thank you

But I had trouble with reset button - nothing happens (all the selected items remain selected)
of course I changed ListBoxName to the proper name

and I need a bit more help on counter :(

Regards,
Ilija
0
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 16293280
Ilija,

I'll have to look further into "reset".

To get your counter:

1) Add the function to a VB module (hit Alt+F11 to get to the VB Editor; select Insert|Module from the menu;
paste my code in the module)

2) Go to your form, add a textbox, and rightclick it to bring up properties.  Go to the controlsource (on data
tab), and enter (assuming form name is "MyForm" and the listbox is named "MyList"):
=SelectedInListbox("MyForm", "MyList")
That should give a count of the number of items selected

Patrick
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
LVL 58

Accepted Solution

by:
harfang earned 600 total points
ID: 16295381
Hello,

It's easier that than, in fact.

To get a "selection count", create a textbox with this control source:

    = lstTheList.ItemsSelected.Count

To reset the selection in the list, use this code:

Private Sub cmdResetList_Click()
    Dim varI
    For Each varI In lstTheList.ItemsSelected
        lstTheList.Selected(varI) = False
    Next varI
    Me.Recalc   ' needed for the text box with selection count...
End Sub

Hope this helps (and sorry to barge in, Patrick)
(°v°)
0
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 16295491
Not at all, Markus.  Simpler = better :)

Patrick
0
 

Author Comment

by:IlijaK
ID: 16297787
Thanks Patrick and Harfang

you solved my problem - I'll have to split the points :)


BTW Harfang if I dont trouble you too much how to modify the code not to reset the selected but to selecta all items in the list

of course lstTheList.Selected(varI) = True does not work
0
 
LVL 58

Expert Comment

by:harfang
ID: 16303175
Ah, that would be:

Private Sub cmdSelectAll_Click()
    Dim lngI As Long
    With lstTheList
        For lngI = 0 To .ListCount - 1
            .Selected(lngI) = True
        Next lngI
    End With
End Sub

The loop in the previous code sample only loops through selected items, this one loops through all items.

Cheers!
(°v°)
0
 

Author Comment

by:IlijaK
ID: 16306478
Tried the code it works but in 10min on 3GHz computer it didn't finish going through the list (10 000 items) :(
any way to speed it up? or open the list already selected?
 I'll increase the points of course
0
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 16306521
Ilija,

I am assuming you are using the ListBox to help users make selection criteria for something,
probably a report or query.

If you have that many items in your list, rather than "select all" that way, I would suggest instead that
you have an Option Group that asks whether to "select all" or to "select one or more".

If "select all" is chosen, disable the ListBox, and let your query use a simplified query.  If not, then
enable the ListBox, and use the more complicated WHERE clause.

Is this at all helpful?

Patrick
0
 
LVL 58

Expert Comment

by:harfang
ID: 16306531
Sorry, there is no way to speed it up.

The problem is that you are using the wrong tool. There isn't anything useful you can possibly do with a selection among 10000 items in a listbox control. For instance, you can't save the selection over sessions, and with such a list, the user might need a couple of days to finalize her selection. Really, navigating and selecting items in such a list is a user's nightmare.

Incidentally, it's also a programmers nightmare, are you are starting to discover. Will you later have to write a query based on the selection of 8342 items in that list? It will be a looooooong query to write, execute and use...

As a rule of thumb: if you have more that 100 items, it's no longer suited for a listbox.

Alternative:

Add a yes/no field to the underlying table and display the list as a subform. Queries to "select all" and "deselect all" will run in a flash (simple update queries) and you have many more options:
* filter/sort the list in various ways to help the selection
* tools to select items by criteria
* collaborate with other users to create the selection

Also, this type of selection will be actually saved in the field, so that one can continue working on it the next day.

If you care to explain a little bit about the setup and purpose of the list, we might have other ideas.

Cheers!
(°v°)
0
 

Author Comment

by:IlijaK
ID: 16339536
Thank you very much for your thorough and fast replies!
0
 

Author Comment

by:IlijaK
ID: 16339544
I can manage select all by using MultiSelect = Extended and shift key
it will suffice for now :)
0
 
LVL 58

Expert Comment

by:harfang
ID: 16339583
I'm glad it worked out. Good luck with your application.
(°v°)
0

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question