FindFirst on Listbox Recordset?

  • Thread starter Thread starter Max Moor
  • Start date Start date
M

Max Moor

Hi All,
I know I can scroll a subform to a specific record using a statement
like:

Me!fsub.Form.Recordset.FindFirst "[DataID] = " & Me!cboBox.Column(2)

I notice that a Listbox also has a recordset property. Is there a
way to scroll a listbox in a like manner? More so, can it be done with
criteria based on other than the bound column?

Note... this doesn't work...

Me!lstBox.Recordset.FindFirst "Column(1) = " & Me!cboBox.Column(1)



- Max
 
Max Moor said:
Hi All,
I know I can scroll a subform to a specific record using a
statement like:

Me!fsub.Form.Recordset.FindFirst "[DataID] = " & Me!cboBox.Column(2)

I notice that a Listbox also has a recordset property. Is there a
way to scroll a listbox in a like manner? More so, can it be done
with criteria based on other than the bound column?

Note... this doesn't work...

Me!lstBox.Recordset.FindFirst "Column(1) = " & Me!cboBox.Column(1)

You can do some interesting things with the recordset of a list box, and
you can in fact navigate in it using the FindFirst method, provided that
you specify the correct field in your criteria string. For example,

Me!lstBox.Recordset.FindFirst "ID = " & Me!cboBox.Column(1)

Unfortunately, doing this doesn't cause the list box to scroll, so it's
no good for what you want. However, Stephen Lebans has posted a
technique for scrolling a list box to any specific row; here's the URL:

http://www.lebans.com/List_Combo.htm#ScrollListbox

You should be able to adapt that code to do what you want. The only
thing you need to do is figure out which row of the list box contains
the field value you're looking for.
 
code loops through the items in the list box and checks if the value i
column 1 matches the value in column 1 of combobox cboBox. If found
the .Selected property of the listbox is used to set the value of th
list box. hope this helps.

Code
-------------------

Dim i As Integer
Dim foundVal as Boolean

i = 0
foundVal = False

Do foundVal
If Me.lstBox.Column(1, i) = Me.cboBox.Column(1) Then
Me.listBox.Selected(i) = True
foundVal = True
End If
i = i + 1
Loop
 
Back
Top