Handling Multiple selects in a form

  • Thread starter Thread starter Bill
  • Start date Start date
B

Bill

I need to implement the equivelent of how Windows
Explorer handles multiple selects, (which is also how
most list oriented Windows applications work). That
is, the user holds down the Ctrl key and selects one
row at a time to essentially build a collection of
whatever is being displayed with each remaining
highlighted as he/she progresses. Then, right-clicks
anywhere within the highlighted items and chooses
the function desired for the collection via a shortcut
menu.

The first approach that comes to mind, is to insert
each selection into what would become the equivelent
of a query that has a "list" of record ID's as its
"selection criteria". That way, the query is simply
the recordsource for whatever function is choosen
by the user. E.g., SELECT from "name of current
form's Recordsource" blah blah blah WHERE
RecordID = (ID1, ID2, ID3, ID4.....IDn). I'm a bit
rusty on how to build the SELECT in code, but I can
probably fumble my way through that, having work
I did a year ago as my guide.

Once again, if what I've described above is what
would be considered a preferred approach, I need
to learn how to:

1) Retain highlighting for each record selected.

2) How to sense if the Crtl key is depressed so as to
trigger insertion of the RecordID into the WHERE
clause of the SQL SELECT described above.

3) Revert highlighting from item 1) above.

4) Given it's possible, how to build the WHERE clause
for the SQL SELECT.

5) Make the temporary recordset created by the query
visable to code outside of the forms codesheet.

I'll stop with the questions here until my approach is
deemed appropriate by reader(s) of this post. I'll try
to stay out of trouble while I await a reply... hahaha!

As always, thanks and blessings to you all.

Bill
 
You can use a Listbox to create this functionality. The Listbox has a
Multiselect property that can be set to allow this. Then you can build a
query in code and save it so that it can be used by a form or report.

On my website (www.rogersaccesslibrary.com) is a small sample database
called "CreateQueries2.mdb" which should help. One of the examples in this
database uses a Listbox.

--
--Roger Carlson
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L
 
Yes, I can see where a Listbox would give me a place to temporarily
store the ID's of items selected. However, I was hoping that I could
make it functional using the same user actions that Windows Explorer
uses. I gather from you reply that isn't possible to mimic Explorer in
code?

Thanks,
Bill
 
I'm not sure what you mean. This IS the same user action that Windows
Explorer uses. Holding the control key allows you to select multiple values
in the listbox where the Multi Select property has been set to Simple or
Extended.

The listbox is not the place to temporarily store the selected items. The
listbox lists all of the items and you select the ones you want. From that
point, you need to do some programming to read what those selected items
are. As I show in the example I mentioned, I would programmatically create
a query and then use that as the Recordsource for a form or report.

--
--Roger Carlson
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L
 
AH! I didn't relate what you'd offered correctly. The current form that
that I have displays record fields in a set of Textboxes across a row
in Continuous mode. If I now understand what you're saying, you would
have me re-vamp the form to use a Listbox such that the record information
is instead displayed in a more-or-less full screen from which the user
selects?

Bill
 
The listbox is not a bad way here.

You can also add a check box as a un-bound column to a continues form..

Try downloading my multi-select example here:
http://www.members.shaw.ca/AlbertKallal/msaccess/msaccess.html

The above takes the uses un-bound check box (beside each record), and then
uses that as a filter for the report. The code that filters the report is
very identical to that of a listbox..but I often the above check box
approach is preferred.
 
Albert,
My ISP might have cause the problem. I disconnected and
reconnected. Your page came up right away.
Bill
 
Albert,
I get an error: "Invalid procedure call or agument", runtime code = 5. The
error occured in function "IsChecked". The statement flagged is:
lngID = colCheckBox(CStr(vID))

Bill
 
Hum, I just re-loaded that page (in fact, you likely where trying to access
the page as I was uploading it!!).

Try downloading that copy I have there now..there was a stray reference in
that file (due to testing).

The one there now should work....
 
Same error Albert and at the same statement as before.
As one clicks on the error "End", the error repeats for
each of the unbound checkboxes.
 
I can't figure out why the IsChecked function is invoked at
Load/Open time. The only path I see is if there has been
a "Click" on the Command13 button?

As an aside, there's no OnLoad or OnOpen code, so how
or when does the colCheckBox Collection get allocated?
Or, is there even the notion of storage allocation for
Collections?

Bill
 
Hey Albert, what happens when you make a reference like
lngID = colCheckBox(CStr(vID)) when the Collection is
empty? "vID" has a value of "1", but there isn't any such
member in the Collection at Load/Open time.

Just a thought,
Bill
 
Bill said:
Hey Albert, what happens when you make a reference like
lngID = colCheckBox(CStr(vID)) when the Collection is
empty? "vID" has a value of "1", but there isn't any such
member in the Collection at Load/Open time.

If the collection is empty, then the function will return false, as I have a
on error goto that traps the above case...

I have no idea why that sample does not work on your machine. Lots of people
download it..and it works fine for them. And, I just tried the code on a pc
with a2000, and it again works just fine. I am running a2003..and it also
works just fine....

I would consider doing a de-compile,and then re-compiling my sample.....but
people downloading and running that sample have not had problems....
 
Try re-downloading this again.

When I uploaded the fix...I had a capital M in the file name. When you
download from the web, it is caps sensitive.

So, my earlier comments about a reference problem in the uploaded file
remains. You can either download the file again, or go into
tools->references...and un-check the Microsoft Active Data Objects (2.5)...

And, make sure you hit refresh in your browser before you re-load if you try
the download again.

I am kind of happy, (and sorry to you) that you had to get bitten by this
reference error....(does the "bad" download you have actually compile ok?).

So, go to the page....hit refresh in your browser..and try downloading it
again...you should be ok...
 
I've been gone for that last 3 hours.....

I downloaded a fresh copy from your site. Still get the same
error when I open the database.

The downloaded code had 5 references checked:
1) Visual Basic For Applications
2) Microsoft Access 9.0 Object Library
3) OLE Automation
4) Microsoft DAO 3.6 Object Library
5) Microsoft ActiveX Data Objects(2.5)

Per your instructions, I unchecked the ActiveX reference.
I then tried to re-compile the database, but the compile
option is disabled. If that sequence of steps required that
I first un-compile the database, then I have more to do to
comply with your instructions. I can't find where one is
given the option to "un-compile".

Bill
 
Roger,
I looked at the possibility of using a Listbox and have examined
"Create Queries2.mdb" in the process. I see what you mean about
the ability to make multiple selections within the Listbox. With that,
how can I use a right-click on one of the highlighted items to get a
popup (shortcut menu) of user options. As it is, when I right-click
one of the selected items, it un-highlights that item, rather than leaving
it selected. (I did create a shortcut menu and add it to the Listboxes
property table, I get the popup of course when I right-clicked, but
that made no difference to the de-selection I've already described.

The application I'm looking to embellish is about 2 years old with a
great deal of functionality on each of two forms. I'm afraid if I were
to replace those forms with the use of a Listbox that I would destroy
the existing functionality, not to mention driving the users "up the wall".

Perhaps I could add a sub-form comprised of a Listbox that is made
visible when items were to be collected for a bulk operation. That is,
the user would select items from the continuous forms as they now
exist and I would insert the selection into the Listbox so that they could
see their selection overlaying the parent. I could also see inserting their
selection into a Collection, but I don't know how to keep the user
informed of their selections... at least I don't know of any way to display
the contents of a Collection as I would with a Sub-form comprised of
an expandable Listbox.

Am I out on a limb here?

Thanks,
Bill
 
As for the Right-click thing, I think you are out of luck (I never said the
listbox would perfectly match the funtionality of Explorer). The Listbox
has no right-click event to trap.

As far as your application, you'll have to decide what you want to do. I
don't know of any way to get the multi-select functionality from a
continuous form. What I would do is have a separate form with the Listbox
open instead of your existing form. The user selects the records they want
and then the new form opens your existing form based on the query created by
the listbox form. This may or may not fit your scenerio, but it's the best
I can offer.

Good luck

--
--Roger Carlson
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L
 
Hum, try un-checking:
5) Microsoft ActiveX Data Objects(2.5)

In the version that I up-loaded, I have removed the above

5) Microsoft ActiveX Data Objects(2.5)

What version of ms-access are you running?
 
Back
Top