Good afternoon:
I am using the following code to auto complete a combo box. However, if I type "I" and beyeon I get an over flow error. The combobox contains over 12000 records coming from a database. Any help would be greatly appreciated. Thank you.
Public Sub SelectItem(cbo As ComboBox, KeyAscii As Integer)
Dim lReturnValue As Long
Dim sFindString As String
Dim gg As Long
If KeyAscii < 32 Or KeyAscii > 127 Then Exit Sub
If cbo.SelLength = 0 Then
sFindString = cbo.Text & Chr$(KeyAscii)
Else
sFindString = Left$(cbo.Text, cbo.SelStart) & Chr$(KeyAscii)
End If
lReturnValue = SendMessage(cbo.hWnd, CB_FINDSTRING, -1, ByVal CStr(sFindString))
'On Error Resume Next
If lReturnValue <> CB_ERR Then
'If lReturnValue <= cbo.ListIndex - 1 Then 21682
gg = lReturnValue
cbo.ListIndex = lReturnValue
cbo.SelStart = Len(sFindString)
cbo.SelLength = Len(cbo.Text) - cbo.SelStart
'End If
End If
KeyAscii = 0
End Sub
I am using the following code to auto complete a combo box. However, if I type "I" and beyeon I get an over flow error. The combobox contains over 12000 records coming from a database. Any help would be greatly appreciated. Thank you.
Public Sub SelectItem(cbo As ComboBox, KeyAscii As Integer)
Dim lReturnValue As Long
Dim sFindString As String
Dim gg As Long
If KeyAscii < 32 Or KeyAscii > 127 Then Exit Sub
If cbo.SelLength = 0 Then
sFindString = cbo.Text & Chr$(KeyAscii)
Else
sFindString = Left$(cbo.Text, cbo.SelStart) & Chr$(KeyAscii)
End If
lReturnValue = SendMessage(cbo.hWnd, CB_FINDSTRING, -1, ByVal CStr(sFindString))
'On Error Resume Next
If lReturnValue <> CB_ERR Then
'If lReturnValue <= cbo.ListIndex - 1 Then 21682
gg = lReturnValue
cbo.ListIndex = lReturnValue
cbo.SelStart = Len(sFindString)
cbo.SelLength = Len(cbo.Text) - cbo.SelStart
'End If
End If
KeyAscii = 0
End Sub