?
Solved

value in text box selects the same value in list box

Posted on 2014-07-24
4
Medium Priority
?
576 Views
Last Modified: 2014-07-25
i have a list box on a form which has around 700 entries. to keep from scrolling back and forth in the list box i would like to type a value in a text box that corresponds to a value in the list box. this would make that selection highlighted.
0
Comment
Question by:cazink
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 

Author Comment

by:cazink
ID: 40218149
MSACCESS
0
 
LVL 25

Accepted Solution

by:
chaau earned 2000 total points
ID: 40218325
I think what you want to do is to implement a search by the value typed in the text box. It can be done easy enough.
Create a TextBox (call it txtSearch) on the form. In the VBA Code for the "Change" event type this code:
Dim iLen as Integer
iLen = Len(txtSearch.Text)
If iLen > 0 Then
For intCurrentRow = 0 To ListBox1.ListCount - 1 
 If Left(ListBox1.Column(0, intCurrentRow),iLen) = txtSearch.Text Then
  ListBox1.Selected(intCurrentRow) = true
  Exit For
 End If 
Next intCurrentRow 
End If

Open in new window

If you have troubles create a sample database with a form with a ListBox with a few items and upload it here. I will modify it and add a search box
0
 
LVL 85
ID: 40219240
Or change the Listbox to a Combo, which has AutoComplete. Then, when you type into the Combobox, Access will automatically search for your value.
0
 

Author Closing Comment

by:cazink
ID: 40220358
hello and thank you, a few changes were made: first i had a txt box on the form so i changed that name, normal, but i had to change the on change property to after update. if there is only one character then on change will work, but if you type the second character it bombs. and since i was looking to match a value in another column then i had to change the column value. also had to declare the variables.
thanks for the help
Dim iLen As Integer
Dim intCurrentRow As Integer
iLen = Len(txtGoTo.Text)
If iLen > 0 Then
For intCurrentRow = 0 To Me.lboMembers.ListCount - 1
 If Left(Me.lboMembers.Column(2, intCurrentRow), iLen) = txtGoTo.Text Then
  Me.lboMembers.Selected(intCurrentRow) = True
  Exit For
 End If
Next intCurrentRow
End If
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question