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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Search Listbox vs Table Query 1
Non Update Form 6
Access Cannot select items in listbox 1
Requery listbox 1
Listbox problem 3
Listbox Scroll Bar 1
Faster DCount or Query 6
Transfer items from one listbox to another 4

Back
Top