use command button to select all records in a list box in Access

G

Guest

As part of a reports database for a school, I have a form (frmPrintSetLists)
used to select classes so that class lists & photos can be printed. There are
4 sets of list boxes on the form with the first three (subjects ; year groups
; teachers) used to filter the classes in the fourth list box (classes). The
classes list box (LstClasses) is multi select. The other list boxes are
single select only.
Printing lists / photos works fine if I select one or many classes manually.
I also have a button to clear selections already made.
I want to add a command button allowing me to select all records in the
classes list box. This should be easy but I can't see how to code this.
Also if I try to make any of the first three list boxes multi select 9e.g.
to select 2 year groups), the filtering process stops working. Can this be
solved?

Thanks in advance

Colin
 
D

Dirk Goldgar

ridders said:
As part of a reports database for a school, I have a form
(frmPrintSetLists) used to select classes so that class lists &
photos can be printed. There are 4 sets of list boxes on the form
with the first three (subjects ; year groups ; teachers) used to
filter the classes in the fourth list box (classes). The classes list
box (LstClasses) is multi select. The other list boxes are single
select only.
Printing lists / photos works fine if I select one or many classes
manually. I also have a button to clear selections already made.
I want to add a command button allowing me to select all records in
the classes list box. This should be easy but I can't see how to code
this.
Also if I try to make any of the first three list boxes multi select
9e.g. to select 2 year groups), the filtering process stops working.
Can this be solved?

Thanks in advance

Colin

------ example code to select all items in a multiselect list box ------
Dim lngX As Long

With Me.lstMyListbox
For lngX = Abs(.ColumnHeads) To (.ListCount - 1)
.Selected(lngX) = True
Next
End With
------ end code ------

For your purposes, replace "lstMyListbox" with "LstClasses".
 
G

Guest

Dirk Goldgar said:
------ example code to select all items in a multiselect list box ------
Dim lngX As Long

With Me.lstMyListbox
For lngX = Abs(.ColumnHeads) To (.ListCount - 1)
.Selected(lngX) = True
Next
End With
------ end code ------

For your purposes, replace "lstMyListbox" with "LstClasses".

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
G

Guest

Thanks. This worked a treat.
Any ideas about my other question regarding multiselect list boxes

Cheers
 
D

Dirk Goldgar

ridders said:
Thanks. This worked a treat.
Any ideas about my other question regarding multiselect list boxes

Your current code probably assumes that the list boxes are
single-select, so it uses each list box's Value property to build a
criterion of the form "FieldName = <value of list box>". Multiselect
list boxes don't have a Value as such; instead, you have to loop
through the list box's ItemsSelected collection and build a criterion of
the form "FieldName In (value1, value2, value3 [, ...])". The logic is
thus somewhat different.

If that's not enough for you to work out the necessary code revisions
yourself, post back with the code you're using currently and I'll see if
I can adapt it for you. However, I'm pretty busy right now, so I can't
say how soon I'll get to it. If you can figure it out yourself, that
would be better.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top