Select rows in list box using VBA

T

TimTDP

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?
 
B

Brendan Reynolds

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
 
T

TimTDP

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
 
Top