Is there a way to mark all list box entries by VBA code.
Is there a way to mark all list box entries by VBA code.

This month, every Windows Secrets subscriber can download a one-chapter excerpt of Windows 7: The Missing Manual.Windows 7: The Missing Manual provides valuable information to help you overcome these difficulties in learning a new operating system. Subscribe today to download your free excerpt.
Do you mean that you want to select all items? Is it a multi-select list box?
[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
Regards
John
[quote name='johnhutchison' post='771509' date='21-Apr-2009 19:20']Here is the code for a "Select All" button
[/quote]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
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.
John Hutchison's code will select and hence highlight all items in the list box (i.e. white text on a black background).
[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
[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.
[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