Solved

value in text box selects the same value in list box

Posted on 2014-07-24
4
564 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
  • 2
4 Comments
 

Author Comment

by:cazink
ID: 40218149
MSACCESS
0
 
LVL 24

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 84
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
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.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now