Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / September 2005

Tip: Looking for answers? Try searching our database.

Select *all* items in listbox

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
RD - 06 Sep 2005 23:44 GMT
Hi all,

I want to be able to select *all* the items of a listbox.  Is there a way to do
this with a single statement or do I have to loop through it using the ListCount
property?

Thanks,
RD
Douglas J. Steele - 07 Sep 2005 00:23 GMT
You need to loop.

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

> Hi all,
>
[quoted text clipped - 6 lines]
> Thanks,
> RD
RD - 07 Sep 2005 15:44 GMT
>You need to loop.

Yeah, I was afraid of that.  I've already written the loop, I was just wondering
if there wasn't something like a Me.listbox.SelectAll kind of thing.

Oh well.

Thanks for the response.

Regards,
RD
Douglas J Steele - 07 Sep 2005 18:50 GMT
Create a generic function (in a module, not associated with a form), and
call it whenever you need it.

Sub ListboxSelectAll(WhatList As ListBox)

Dim intCurrentRow As Integer

  For intCurrentRow = 0 To WhatList.Listcount - 1
    WhatList.Selected(intCurrentRow) = True
  Next intCurrentRow

End Sub

In your code, you'd use something

  Call ListboxSelectAll Me!MyListBox

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

> >You need to loop.
>
[quoted text clipped - 7 lines]
> Regards,
> RD
RD - 08 Sep 2005 16:00 GMT
>Create a generic function (in a module, not associated with a form), and
>call it whenever you need it.
[quoted text clipped - 12 lines]
>
>   Call ListboxSelectAll Me!MyListBox

Excellent!  A new item for my library.

Thanks,
RD
Pete - 07 Sep 2005 13:06 GMT
If you want to add a button that will let your users Select/Deselect All the
following code will do this:

Private Sub cmdSelectAll_Click()
   Dim n As Integer, i As Integer
   If Me.cmdSelectAll.Caption = "Select All" Then
       i = 1
       Me.cmdSelectAll.Caption = "De-Select All"
   Else
       i = 0
       Me.cmdSelectAll.Caption = "Select All"
   End If
   For n = 0 To Me.lstMyList.ListCount - 1
       Me.lstMyList.Selected(n) = i
   Next n
End Sub

Signature

Peter Schmidt
Ross-on-Wye, UK

> Hi all,
>
[quoted text clipped - 4 lines]
> Thanks,
> RD
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.