txtAutoCompl



Public IsDelOrBack As Boolean
Public Function AutoComplete(TheText As TextBox, _
TheDB As Database, TheTable As String, _
TheField As String) As Boolean

On Error Resume Next
Dim OldLen As Integer
Dim dsTemp As Recordset
AutoComplete = False
If Not TheText.Text = "" And IsDelOrBack = False Then
OldLen = Len(TheText.Text)
Set dsTemp = TheDB.OpenRecordset _
("Select * from " & TheTable & " where " & TheField & _
" like '" & TheText.Text & "*'", dbOpenDynaset)

If Err = 3075 Then
'here we got a bug!!

End If
If Not dsTemp.RecordCount = 0 Then
TheText.Text = dsTemp(TheField)
If TheText.SelText = "" Then
TheText.SelStart = OldLen
Else
TheText.SelStart = InStr(TheText.Text, TheText.SelText)
End If
TheText.SelLength = Len(TheText.Text)
AutoComplete = True
End If
End If
End Function

Public Function CheckIsDelOrBack(TheKey As Integer) As Boolean
'TheKey is the KeyAscii - all you gotta do is write

'CheckIsDelOrBack(KeyAscii) on the KeyDown event...

If TheKey = vbKeyBack Or TheKey = vbKeyDelete Then
IsDelOrBack = True
CheckIsDelOrBack = True
Else
IsDelOrBack = False
CheckIsDelOrBack = False
End If
End Function



(txtautocompl.html)- by Paolo Puglisi - Modifica del 25/3/2019