AUTOCOMPLEMENTO COMBO
Sei q tem varios topicos sobre combo, mas pesquisei todos e nao achei um q resolvesse....uso uma conexao RDO e tenho uma combo, gostaria q conforme o usuario fosse digitando o nome do cliente ia aparecendo o nome do cliente q esta cadastrado na tabela CLIENTE via sql.....se alguem poder me ajudar agradeço......
DIOGOMUNARIN, melhorei essa sub, que peguei aqui mesmo e uso no meu sistema assim, vê se é o que procura.
Public Sub PesqCombo(ctlCombo As ComboBox, intCodTecla As Integer)
On Error GoTo SaiDoErro 'Tratamento que evita erros
Static NoSelectText As String 'Armazena o texto digitado
Dim i As Long 'Variavel do for
With ctlCombo '
'Se as teclas de movimentacao forem acionadas sai da sub
If intCodTecla = vbKeyUp Then Exit Sub
If intCodTecla = vbKeyDown Then Exit Sub
If intCodTecla = vbKeyLeft Then Exit Sub
If intCodTecla = vbKeyRight Then Exit Sub
If intCodTecla = vbKeyPageUp Then Exit Sub
If intCodTecla = vbKeyPageDown Then Exit Sub
If intCodTecla = vbKeyEnd Then Exit Sub
If intCodTecla = vbKeyHome Then Exit Sub
If intCodTecla = vbKeyReturn Then Exit Sub
'Se a tecla for diferente de backspace
If intCodTecla <> vbKeyBack Then
NoSelectText = Mid(.Text, 1, Len(.Text) - .SelLength)
Else
If NoSelectText <> "" Then
NoSelectText = Mid(NoSelectText, 1, Len(NoSelectText) - 1)
End If
End If
'Faz a procura no combo
For i = 0 To .ListCount - 1
If UCase(NoSelectText) = UCase(Mid(.List(i), 1, Len(NoSelectText))) Then
.ListIndex = i
Exit For
End If
Next
'Seleciona a parte que nao foi digitada automaticamente
.SelStart = Len(NoSelectText)
.SelLength = Len(.Text)
End With
SaiDoErro:
End Sub
Você a utiliza no evento KeyUp do combo:
Private Sub Combo1_KeyUp(KeyCode As Integer, Shift As Integer)
PesqCombo Combo1, KeyCode
End Sub
Valeu?
Public Sub PesqCombo(ctlCombo As ComboBox, intCodTecla As Integer)
On Error GoTo SaiDoErro 'Tratamento que evita erros
Static NoSelectText As String 'Armazena o texto digitado
Dim i As Long 'Variavel do for
With ctlCombo '
'Se as teclas de movimentacao forem acionadas sai da sub
If intCodTecla = vbKeyUp Then Exit Sub
If intCodTecla = vbKeyDown Then Exit Sub
If intCodTecla = vbKeyLeft Then Exit Sub
If intCodTecla = vbKeyRight Then Exit Sub
If intCodTecla = vbKeyPageUp Then Exit Sub
If intCodTecla = vbKeyPageDown Then Exit Sub
If intCodTecla = vbKeyEnd Then Exit Sub
If intCodTecla = vbKeyHome Then Exit Sub
If intCodTecla = vbKeyReturn Then Exit Sub
'Se a tecla for diferente de backspace
If intCodTecla <> vbKeyBack Then
NoSelectText = Mid(.Text, 1, Len(.Text) - .SelLength)
Else
If NoSelectText <> "" Then
NoSelectText = Mid(NoSelectText, 1, Len(NoSelectText) - 1)
End If
End If
'Faz a procura no combo
For i = 0 To .ListCount - 1
If UCase(NoSelectText) = UCase(Mid(.List(i), 1, Len(NoSelectText))) Then
.ListIndex = i
Exit For
End If
Next
'Seleciona a parte que nao foi digitada automaticamente
.SelStart = Len(NoSelectText)
.SelLength = Len(.Text)
End With
SaiDoErro:
End Sub
Você a utiliza no evento KeyUp do combo:
Private Sub Combo1_KeyUp(KeyCode As Integer, Shift As Integer)
PesqCombo Combo1, KeyCode
End Sub
Valeu?
Ainda nao deu certo...vou explicar melhor: eu queria q a combo busca-se so os clientes q tenho cadastrado na tabela CLIENTE e fosse completando conforme o usuario fosse digitando entenderam...se alguem poder me ajudar agradeço...
Tópico encerrado , respostas não são mais permitidas