Handling Multiple selects in a form

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
 
R

Roger Carlson

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
 
B

Bill

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
 
R

Roger Carlson

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
 
B

Bill

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
 
A

Albert D. Kallal

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.
 
B

Bill

Albert, I got a "Page cannot be displayed" on the link you sent. Is the
server down?

Bill
 
B

Bill

Albert,
My ISP might have cause the problem. I disconnected and
reconnected. Your page came up right away.
Bill
 
B

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
 
A

Albert D. Kallal

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....
 
B

Bill

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.
 
B

Bill

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
 
B

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
 
A

Albert D. Kallal

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....
 
A

Albert D. Kallal

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

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