Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Type ahead feature

Status
Not open for further replies.

FredNg

Programmer
Jun 25, 2003
4
MU
Hi

I am trying to replicate some features of my accounting software and one of them is the type ahead meaning say when I key in the letter F in the text box, it should automatically find all the customers with names starting with f from the recordset and list it in the datagrid. Then when I key in the next word say fa it should find the closest match and so on.

Any idea how to do it ?

Thanks in advance
 

What may be easier and less costly to your server and network is to populate a combo box with all of the customer names. Then you could use a modified SendMessage API to find the string you want.

This example needs a textbox, listbox, and combo box...
[tt]
Option Explicit

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function SendMessageString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As String, ByVal lParam As String) As Long

Private Const LB_FINDSTRING = &H18F
Private Const LB_FINDSTRINGEXACT = &H1A2

Private Sub Form_Load()

On Error GoTo Form_LoadError

List1.AddItem "Test String"
Combo1.AddItem "Test String"
List1.AddItem "Information"
Combo1.AddItem "Information"
List1.AddItem "This is a test"
Combo1.AddItem "This is a test"
List1.AddItem "We have a test to run"
Combo1.AddItem "We have a test to run"
List1.AddItem "Can you run this test"
Combo1.AddItem "Can you run this test"
List1.AddItem "All this is is a test"
Combo1.AddItem "All this is is a test"
List1.AddItem "Because We are running a test"
Combo1.AddItem "Because We are running a test"
List1.AddItem "Zebra Test"
Combo1.AddItem "Zebra Test"
List1.AddItem "My test string"
Combo1.AddItem "My test string"
List1.AddItem "Final test string"
Combo1.AddItem "Final test string"


Exit Sub
Form_LoadError:

MsgBox Err.Description

End Sub

Private Sub Text1_Change()

On Error GoTo Text1_ChangeError

Dim ReturnValue As Long, I As Integer

ReturnValue = SendMessageString(List1.hwnd, LB_FINDSTRING, Text1.Text, Text1.Text)

If ReturnValue >= 0 Then

List1.ListIndex = ReturnValue
'List1.Selected(ReturnValue) = True
Combo1.Text = Combo1.List(ReturnValue)

Else

Combo1.Text = ""
For I = 0 To List1.ListCount - 1
List1.Selected(I) = False
Next I

End If

Exit Sub
Text1_ChangeError:

MsgBox Err.Description

End Sub
[/tt]

Good Luck

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top