Debmedia Creation Forum
Would you like to react to this message? Create an account in a few clicks or log in to continue.

VB autocomplete textbox and listbox

Go down

VB autocomplete textbox and listbox Empty VB autocomplete textbox and listbox

Post  Admin Wed Jan 27, 2010 4:49 pm

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
Admin
Admin
Admin

Posts : 256
Join date : 2008-06-06

https://debmedia.forumotion.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum