Select First Row of a Value in ListBox (1 Viewer)

gstreichan

Registered User.
Local time
Today, 09:16
Joined
Apr 1, 2014
Messages
28
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
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 03:16
Joined
May 21, 2018
Messages
8,529
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

  • SelectFirst.accdb
    2.1 MB · Views: 56
Last edited:

Users who are viewing this thread

Top Bottom