Solved

value in text box selects the same value in list box

Posted on 2014-07-24
4
572 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 500 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

691 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