Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Other Forums
 MS Access
 "On Key Down" property to search a list

Author  Topic 

pgill
Starting Member

17 Posts

Posted - 2007-11-29 : 00:14:37
I have a form that displays customer information in a list. I have a text box to search for a specific customer in the list. What I would like to do is that as the user types the customer name it goes to the customer as the user types in the name. An example of this is in the index view of the help file. If you type in the letter 'b' it goes to the 'b' topic, as you type and you then type the letter 'r' (so now you have 'br') it goes to the topic begining with 'br' such as break. Should I use the "On Key Down" property and if so how should I code it? Can any one tell me how to do this? Thanks in advance.

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-11-29 : 10:41:32
I have done this in the past and used the KeyPress event.

Here's an example:

Option Compare Database
Option Explicit

Dim CurrStr As String
Dim LastTime As Date

Private Sub SomeTextBox_KeyPress(KeyAscii As Integer)
If (KeyAscii >= 32) And (KeyAscii <= 127) Then
If DateDiff("s", LastTime, Now()) > 2 Then
CurrStr = ""
End If
LastTime = Now()
CurrStr = CurrStr & Chr(KeyAscii)
DoCmd.FindRecord CurrStr, acStart, , acSearchAll, , acCurrent, True
Else
CurrStr = ""
End If
End Sub


Notice that we have a "time out" feature, that after 2 seconds, the search string is "reset" and you can start over. this should get you started.

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

pgill
Starting Member

17 Posts

Posted - 2007-11-29 : 10:59:05
Wow Jeff, thanks a lot. Your reply is certainly more than I expected. Looks like you gave me everything I need (and exactly what I need). Again, thanks alot I'll give it a try.
Go to Top of Page
   

- Advertisement -