VB autocomplete textbox and listbox
Page 1 of 1
VB autocomplete textbox and listbox
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByRef lParam As Any _
) As Long
Const LB_FINDSTRING = &H18F
Dim rs As ADODB.Recordset
Dim DelKey As Boolean
Dim bNoClick As Boolean
Private Sub Form_Load()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Call MAKECONNECTION(cn, rs, "select * from all_cust")
List1.Clear
If rs.EOF = True Then
MsgBox "NO RECORDS AVAILABLE", vbCritical, "EMPTY RECORD"
Exit Sub
End If
rs.MoveFirst
Do While rs.EOF = False
List1.AddItem rs.Fields("cust_name")
rs.MoveNext
Loop
End Sub
Private Sub Text1_Change()
'autocomplete feature
Dim strt As Long, nIndex As Long
Dim nLen As Long, sText As String
Const LB_GETTEXTLEN As Long = &H18A
Const LB_GETTEXT As Long = &H189
Static blnBusy As Boolean
If blnBusy Then
Exit Sub
End If
bNoClick = True
blnBusy = True
'Retrieve the item's listindex
List1.ListIndex = SendMessage(List1.hwnd, LB_FINDSTRING, -1, ByVal CStr(Text1.Text))
If Not DelKey Then
If List1.ListIndex <> -1 Then
strt = Len(Text1.Text)
Text1.Text = List1.list(List1.ListIndex)
Text1.SelStart = strt
Text1.SelLength = Len(Text1.Text) - strt
Else
End If
End If
DelKey = False
blnBusy = False
bNoClick = False
End Sub
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByRef lParam As Any _
) As Long
Const LB_FINDSTRING = &H18F
Dim rs As ADODB.Recordset
Dim DelKey As Boolean
Dim bNoClick As Boolean
Private Sub Form_Load()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Call MAKECONNECTION(cn, rs, "select * from all_cust")
List1.Clear
If rs.EOF = True Then
MsgBox "NO RECORDS AVAILABLE", vbCritical, "EMPTY RECORD"
Exit Sub
End If
rs.MoveFirst
Do While rs.EOF = False
List1.AddItem rs.Fields("cust_name")
rs.MoveNext
Loop
End Sub
Private Sub Text1_Change()
'autocomplete feature
Dim strt As Long, nIndex As Long
Dim nLen As Long, sText As String
Const LB_GETTEXTLEN As Long = &H18A
Const LB_GETTEXT As Long = &H189
Static blnBusy As Boolean
If blnBusy Then
Exit Sub
End If
bNoClick = True
blnBusy = True
'Retrieve the item's listindex
List1.ListIndex = SendMessage(List1.hwnd, LB_FINDSTRING, -1, ByVal CStr(Text1.Text))
If Not DelKey Then
If List1.ListIndex <> -1 Then
strt = Len(Text1.Text)
Text1.Text = List1.list(List1.ListIndex)
Text1.SelStart = strt
Text1.SelLength = Len(Text1.Text) - strt
Else
End If
End If
DelKey = False
blnBusy = False
bNoClick = False
End Sub
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum