Select First Row of a Value in ListBox

gstreichan

Registered User.
Local time
Today, 19:55
Joined
Apr 1, 2014
Messages
34
Dears,

I have a ListBox0 in a Form that shows all different on hand quantities for a BOM_Pos.
I would like to click on a button and have all first rows for BOM_Pos selected, is it possible?
For instance here below, there are 6 different BOM_Pos and how I am trying to get it to select.
Would appreciate very much if someone can help me. Thank you.

1689171451133.png
 
Code:
Public Sub GoToFirstRow(lst As Access.ListBox, ColumnNumber As Integer, Val As Variant)
  Dim i As Integer
  For i = 0 To lst.ListCount - 1
    ' Debug.Print lst.Column(ColumnNumber, i)
    If lst.Column(ColumnNumber, i) = CStr(Val) Then
      lst.Selected(i) = True
        Exit Sub
    End If
  Next i
End Sub

But you will have to feed that function with something like

Code:
Public Sub SelectAllBom
  dim rs as dao.recordset
set rs = currentdb.openrecordset ("Select Distinct BOM_Pos from SomeTable")
do while not RS.EOF
  GoToFirstRow Me.SomeListBox, 10, rs!BOM_Pos
  rs.moveNext
loop
end sub
see demo

You may also consider something like this
 

Attachments

Last edited:

Users who are viewing this thread

Back
Top Bottom