Solved

value in text box selects the same value in list box

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Familiarize people with the process of utilizing SQL Server views 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 Access…

758 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

23 Experts available now in Live!

Get 1:1 Help Now