Find in Listbox

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

Guest

I have a listbox with 5 columns. I need to be able to find an entry in
column 2 of the listbox that matches a textfield on a form and then select
that matching entry in the listbox.

Can anyone please help?
 
Peter,

Private Sub YrListBox_AfterUpdate()
' (You can use the click event too)

DoDmd.GoToControl "the field on the table"
DoCmd.FindRecord " ' " & Me.YrListBox.Column(1) & " ' "

End Sub

Remove the spaces in " ' ")
Note: Access count the column number from 0 not 1

Regards/JK
 
PeterM said:
I have a listbox with 5 columns. I need to be able to find an entry
in column 2 of the listbox that matches a textfield on a form and
then select that matching entry in the listbox.

Can anyone please help?

This would probably mean some looping - here some air code

dim lst as listbox
dim lngCounter as long
dim strText as string

strText = trim$(me.controls("txtText").value & "")
if len(strText) then
set lst = me.controls("lstNameOfListbox")
for lngcounter = 0 to lst.listcount
if (strcomp(strText, trim$(lst.column(1, lngcounter)), _
vbTextCompare) = 0) then
lst.Selected(lngCounter) = true
exit for
end if
next lngcounter
set lst = nothing
end if
 
Back
Top