Button to select all in listbox

maverick8888
StarLounger
Posts: 54
Joined: 21 Jun 2011, 03:05

Button to select all in listbox

Post by maverick8888 »

Lounge,

Hello all and Happy New Year. I use the following code in a form to clear all "id's" selected.
Private Sub cmdlboClear_Click()
Dim varSelected As Variant
For Each varSelected In Me.lboJobID.ItemsSelected
Me.lboJobID.Selected(varSelected) = False
Next varSelected
End Sub

Can someone educate me on how to use a button to select all?
Thanks,
Michael

User avatar
HansV
Administrator
Posts: 78412
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Button to select all in listbox

Post by HansV »

Happy New Year to you too! Try this (it assumes that lboJobID has its MultiSelect property set to Simple or Extended):

Code: Select all

Private Sub cmdlboSelectAll_Click()
    Dim i As Long
    For i = 0 To Me.lboJobID.ListCount - 1
        Me.lboJobID.Selected(i) = True
    Next i
End Sub
Best wishes,
Hans

maverick8888
StarLounger
Posts: 54
Joined: 21 Jun 2011, 03:05

Re: Button to select all in listbox

Post by maverick8888 »

Thanks Hans, It did exactly what i wanted, however. :) It took over an hour to process, lol. Maybe i can try a different approach. Let me see if i can explain what im trying to do.

I have a database that is listed by clients a-z (lboJobID) and when selected access will calculate and do wonderful things. For any given day we run mail we use 30-50 clients by various amounts of mail. What im trying to do is see how much money, pieces etc etc for a given date range or even a single day. I tried creating the exact form but changing the lboJOBID to lboMAILID and did the neccessary changes to show that. The problem is that all quieres are based on the form that has JOBID and unless im wrong i would have to duplicate all quieres so that it could point to the new "selection" list box. I imagine there is another way to do this but my inexperience is stopping me. IN theory i guess it would be prime to have the ability to choose whether i was selecting based on MailID or JobID, any thought? The entire idea behind this project is to be able to have historical data on a client but now i see the need to have historical data based on a date range.
Michael

User avatar
HansV
Administrator
Posts: 78412
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Button to select all in listbox

Post by HansV »

How many items does your list box have?

I'm afraid I don't know enough about your database to answer your new question. Could you give us some idea - perhaps attach a stripped down and zipped copy (without proprietary information)?
Best wishes,
Hans

maverick8888
StarLounger
Posts: 54
Joined: 21 Jun 2011, 03:05

Re: Button to select all in listbox

Post by maverick8888 »

Hans,
I emailed you the sample database due to size restraint.

User avatar
HansV
Administrator
Posts: 78412
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Button to select all in listbox

Post by HansV »

I have received the database. What should I look at?
Best wishes,
Hans

maverick8888
StarLounger
Posts: 54
Joined: 21 Jun 2011, 03:05

Re: Button to select all in listbox

Post by maverick8888 »

Sorry, the frmMultiSelectListDemo is the form that is in question. the list box over to the left is "lbojobid" that is the one that i was wondering if there can be some sort of choice to choose if that one lists the items by "jobid" or "MailingID" as the source.

User avatar
HansV
Administrator
Posts: 78412
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Button to select all in listbox

Post by HansV »

I'd create a second tab in the tab control (TabCtl6), with a list box that lists the MailingIDs and a subform that uses the MailingIDs.
Best wishes,
Hans

maverick8888
StarLounger
Posts: 54
Joined: 21 Jun 2011, 03:05

Re: Button to select all in listbox

Post by maverick8888 »

Ok so i did as you said (great idea). I created the second tab. Created Mailing ID list box. created sfrm and used Mailing id but now both selection tabs are not working. I assume that the problem lies in the "idselection" module but do not know how to fix. Also in the two subfroms(both tabs) are not being populated with selections.
Please advise,
Michael

OK now that im done being a complete newbie, The only thing i am lacking is the ability to multi select the mailing ID's and for the selections to populate the sub form in the tab. The original tab is working correctly (always was).
Last edited by maverick8888 on 06 Jan 2012, 01:01, edited 1 time in total.

User avatar
HansV
Administrator
Posts: 78412
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Button to select all in listbox

Post by HansV »

As long as you provide the correct arguments, the IsSelectedVar function should work for both JobID and MailingID. I don't know what causes neither tab to work now.
Best wishes,
Hans

maverick8888
StarLounger
Posts: 54
Joined: 21 Jun 2011, 03:05

Re: Button to select all in listbox

Post by maverick8888 »

I am sorry, those are working now. i edited the previous post. The only thing that is missing is that i cant select more than one sequence and the selection that i make is seeming to select randomly into the sfrm box, not sure why this or what is happening, i will look into it later.

Thank you again for your time.

User avatar
HansV
Administrator
Posts: 78412
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Button to select all in listbox

Post by HansV »

I hope you'll be able to solve that too. If you want more assistance, please provide a copy of the database again, with the latest changes.
Best wishes,
Hans

maverick8888
StarLounger
Posts: 54
Joined: 21 Jun 2011, 03:05

Re: Button to select all in listbox

Post by maverick8888 »

emaeil sent wirh txt document explaining changes/issues

maverick8888
StarLounger
Posts: 54
Joined: 21 Jun 2011, 03:05

Re: Button to select all in listbox

Post by maverick8888 »

I guess the part that i should say is that 80% of the quieres are doing the math per client when that id is selected. Im trying to make it where the sequence selection addition still calculates and processes as if the customer selection was made but i see that is an issue. Better said would be that the quieres for calculations are dependant on the qselIDList query and that one decides the customer selection.

User avatar
HansV
Administrator
Posts: 78412
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Button to select all in listbox

Post by HansV »

I'm looking at your database at the moment, but it might be a while before I have a reply to all your questions. One thing is easy though: You have forgotten to set the MultiSelect property of the lboMailingID list box to Simple. Hence you can't select multiple items in this list box.
Best wishes,
Hans

User avatar
HansV
Administrator
Posts: 78412
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Button to select all in listbox

Post by HansV »

OK, here is a version of the database that needs only a single query, list box and subform. I used an option group to let the user choose between JoobID and MailingID.
I had to add a primary key to the tblBilling table for this, so I imported it into the database itself. This also speeds up performance considerably.

By compacting the database, the size went from 14 MB to 2 MB, and the zip file was small enough to be attached here.
forHans.zip
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans

maverick8888
StarLounger
Posts: 54
Joined: 21 Jun 2011, 03:05

Re: Button to select all in listbox

Post by maverick8888 »

Hans,

You are amazing! Is there anything you dont know how to do in Access? So i relinked the table with the primary key "BillingID" and all is good there. The only thing i am missing is that the lists in the list box repeat all the way down. In the previous version of the database it was simple enough to use the SELECT DISTINCT to only show one of each occurance. As ive never used the option group i am unfamiliar in how to use the DISTINCT option for the MailingID and using it for the JobID with the Primary key in the Select phrase.

Thank you again for your help with this!

Michael

User avatar
HansV
Administrator
Posts: 78412
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Button to select all in listbox

Post by HansV »

There *are* things I don't know how to do - my idea didn't take into account that there could be duplicates in the JobID and MailingID fields. This means that you can't use a unique BillingID field, and you'll have to go back to doing everything twofold: two separate sets of queries, subforms etc.
I'm sorry to have gone off in the wrong direction... :sad:
Best wishes,
Hans

User avatar
HansV
Administrator
Posts: 78412
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Button to select all in listbox

Post by HansV »

Here is a version that does use a single list box.
But it does use separate queries and subforms for JobID and MailingID.
forHans.zip
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans

maverick8888
StarLounger
Posts: 54
Joined: 21 Jun 2011, 03:05

Re: Button to select all in listbox

Post by maverick8888 »

Hans,

Thank you for all your help again. I cant thank you enough for your help. Although I was hoping to make things easier i will enjoy doubling all the quieres and reports. I dont imagine the unused quieres will slow down processing. I am sure you will hear from me again, lol. You are a saint.

Michael