Solved

value in text box selects the same value in list box

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

732 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