Results 1 to 8 of 8
  1. #1
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts
    Is there a way to mark all list box entries by VBA code.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Do you mean that you want to select all items? Is it a multi-select list box?

  3. #3
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    [quote name='patt' post='771503' date='21-Apr-2009 17:37']Is there a way to mark all list box entries by VBA code.[/quote]

    Here is the code for a "Select All" button

    Code:
    Private Sub cmdSelectAllParents_Click()
    	  Dim intItem As Integer
    	   Dim intcount As Integer
    	   Dim lbListbox As ListBox
    	   Set lbListbox = Me!parentlist
    	   intcount = lbListbox.ListCount
    	   For intItem = 0 To intcount - 1
     		 lbListbox.Selected(intItem) = True
     	  Next intItem
     End Sub
    Regards
    John



  4. #4
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts
    [quote name='johnhutchison' post='771509' date='21-Apr-2009 19:20']Here is the code for a "Select All" button

    Code:
    Private Sub cmdSelectAllParents_Click()
    	  Dim intItem As Integer
    	   Dim intcount As Integer
    	   Dim lbListbox As ListBox
    	   Set lbListbox = Me!parentlist
    	   intcount = lbListbox.ListCount
    	   For intItem = 0 To intcount - 1
     		 lbListbox.Selected(intItem) = True
     	  Next intItem
     End Sub
    [/quote]
    That's pretty much my code line for line.
    Isn't it meant to show that they have been selected by shading each line?
    I have a table of items that is the source of this listbox.

    Yes Hans it is multi select.

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    John Hutchison's code will select and hence highlight all items in the list box (i.e. white text on a black background).

  6. #6
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    [quote name='patt' post='771515' date='21-Apr-2009 19:47']That's pretty much my code line for line.
    Isn't it meant to show that they have been selected by shading each line?
    I have a table of items that is the source of this listbox.

    Yes Hans it is multi select.[/quote]

    When I use this code the whole listbox goes black (with white text) !
    Regards
    John



  7. #7
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts
    [quote name='HansV' post='771518' date='21-Apr-2009 21:01']John Hutchison's code will select and hence highlight all items in the list box (i.e. white text on a black background).[/quote]
    Thyanks, I will try it again this morning.
    I will let you know.

  8. #8
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts
    [quote name='johnhutchison' post='771520' date='21-Apr-2009 21:11']When I use this code the whole listbox goes black (with white text) ![/quote]
    Hi John,
    Here is the code that i was using, it is the one commented out.
    Yours is here too, only yours works, the code i got from Access Help doesn't work.
    Thanks

    ' Dim ctl As Control
    ' Dim varItm As Variant
    ' ListHospitals.Requery
    ' If Not IsNull(ListHospitals) Then
    ' Set ctl = ListHospitals
    ' For varItm = 0 To ctl.ListCount - 1
    ' ctl.Selected(varItm) = True
    ' Next varItm
    ' End If

    Dim intItem As Integer
    Dim intcount As Integer
    Dim lbListbox As ListBox
    Set lbListbox = Me!ListHospitals
    intcount = lbListbox.ListCount
    For intItem = 0 To intcount - 1
    lbListbox.Selected(intItem) = True
    Next intItem

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •