Select rows in list box using VBA

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a table which inlcudes the fields:
Product
Use (boolean)

A form contains a List Box bound to this table.
When the form opens I want to automatically select all records where field
"USE" = True
What is the code for this?
 
Something like this should do it ...

Private Sub Form_Load()

Dim lngLoop As Long

For lngLoop = 0 To Me.List0.ListCount - 1
If Me.List0.Column(1, lngLoop) = True Then
Me.List0.Selected(lngLoop) = True
End If
Next lngLoop

End Sub
 
Thank you most kindly

Brendan Reynolds said:
Something like this should do it ...

Private Sub Form_Load()

Dim lngLoop As Long

For lngLoop = 0 To Me.List0.ListCount - 1
If Me.List0.Column(1, lngLoop) = True Then
Me.List0.Selected(lngLoop) = True
End If
Next lngLoop

End Sub
 
Back
Top