Use value in textbox to select item in listbox

G

Guest

There was a KB article that shows how to use a textbox on a form to select an
item in the listbox. As the user types in the value, a matching value is
selected in the listbox. I cannot find that article. Does anyone know where
it is?
 
S

Sandra Daigle

I don't have a KB article but here is some code that should get you
started - the textbox is named 'Text2' and the listbox is named 'list0'.
Note that the "text" property of the control is only available while the
control has focus and it's value is what is currently typed into the
control.

Private Sub Text2_Change()
Dim inti As Integer
Dim fEnd As Boolean
inti = 0

Do Until fEnd
If Left(Me.List0.Column(1, inti), Len(Me.Text2.Text)) = Me.Text2.Text
Then
fEnd = True
Me.List0.SetFocus
Me.List0.ListIndex = inti
' put focus back to the textbox
Me.Text2.SetFocus
Me.Text2.SelStart = Len(Me.Text2 & "")
Else
inti = inti + 1
If inti > Me.List0.ListCount Then
fEnd = True
End If
End If
Loop

End Sub
 
G

Guest

Thank you so much Sandra. The article has a much simpler code. I just don't
remember how to get started. It had something to do with the recordsetclone
property. Still looking for the article.

Sandra Daigle said:
I don't have a KB article but here is some code that should get you
started - the textbox is named 'Text2' and the listbox is named 'list0'.
Note that the "text" property of the control is only available while the
control has focus and it's value is what is currently typed into the
control.

Private Sub Text2_Change()
Dim inti As Integer
Dim fEnd As Boolean
inti = 0

Do Until fEnd
If Left(Me.List0.Column(1, inti), Len(Me.Text2.Text)) = Me.Text2.Text
Then
fEnd = True
Me.List0.SetFocus
Me.List0.ListIndex = inti
' put focus back to the textbox
Me.Text2.SetFocus
Me.Text2.SelStart = Len(Me.Text2 & "")
Else
inti = inti + 1
If inti > Me.List0.ListCount Then
fEnd = True
End If
End If
Loop

End Sub

--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.

There was a KB article that shows how to use a textbox on a form to
select an item in the listbox. As the user types in the value, a
matching value is selected in the listbox. I cannot find that
article. Does anyone know where it is?
 

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

Top