combobox???
Buenas a todos:
Tengo una consulta. Existe alguna manera de que en un combobox me filtre a medida que vaya ingresando caracteres?
He tratado con algo asi pero no funciona:
Private Sub Combo1_Change()
Dim C As String
Dim L As Integer
L=Len(Combo1)
C="Left(Nombre," & Str(L) & ")='" & Combo1 & "'"
Reg.FindFirst C
If Reg.NoMatch Then
....
Endif
En combo lo cargo de datos de una tabla access, pero siempre se sale por NoMatch.
Alguien sabe como???
Gracias
Marcelo
Tengo una consulta. Existe alguna manera de que en un combobox me filtre a medida que vaya ingresando caracteres?
He tratado con algo asi pero no funciona:
Private Sub Combo1_Change()
Dim C As String
Dim L As Integer
L=Len(Combo1)
C="Left(Nombre," & Str(L) & ")='" & Combo1 & "'"
Reg.FindFirst C
If Reg.NoMatch Then
....
Endif
En combo lo cargo de datos de una tabla access, pero siempre se sale por NoMatch.
Alguien sabe como???
Gracias
Marcelo
' Para este ejemplo necesitas un formulario y un combobox llamado Combo1
Dim Combo1Borrado As Boolean
Private Sub Combo1_Change()
Static YaEstoy As Boolean
On Local Error Resume Next
If Not YaEstoy Then
YaEstoy = True
unCombo_Change Combo1.Text, Combo1
YaEstoy = False
End If
Err = 0
End Sub
Private Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer)
unCombo_KeyDown KeyCode
End Sub
Private Sub Combo1_KeyPress(KeyAscii As Integer)
unCombo_KeyPress KeyAscii
End Sub
Private Sub unCombo_KeyDown(KeyCode As Integer)
If KeyCode = vbKeyDelete Then
Combo1Borrado = True
Else
Combo1Borrado = False
End If
End Sub
Private Sub unCombo_KeyPress(KeyAscii As Integer)
'si se pulsa Borrar... ignorar la búsqueda al cambiar
If KeyAscii = vbKeyBack Then
Combo1Borrado = True
Else
Combo1Borrado = False
End If
End Sub
Private Sub unCombo_Change(ByVal sText As String, elCombo As ComboBox)
Dim i As Integer, L As Integer
If Not Combo1Borrado Then
L = Len(sText)
With elCombo
For i = 0 To .ListCount - 1
If StrComp(sText, Left$(.List(i), L), 1) = 0 Then
.ListIndex = i
.Text = .List(.ListIndex)
.SelStart = L
.SelLength = Len(.Text) - .SelStart
Exit For
End If
Next
End With
End If
End Sub
Private Sub Form_Load()
Combo1.AddItem "Carlos"
Combo1.AddItem "Jorge"
Combo1.AddItem "Miguel"
Combo1.AddItem "Javier"
Combo1.AddItem "Marta"
Combo1.AddItem "Pedro"
Combo1.AddItem "Abel"
Combo1.AddItem "Fernando"
Combo1.AddItem "Rafa"
Combo1.AddItem "Jose carlos"
End Sub
salu2
sdemingo
pd. el código no es mÃo, es de Carlos y lo expuso en este foro hace tiempo.
Dim Combo1Borrado As Boolean
Private Sub Combo1_Change()
Static YaEstoy As Boolean
On Local Error Resume Next
If Not YaEstoy Then
YaEstoy = True
unCombo_Change Combo1.Text, Combo1
YaEstoy = False
End If
Err = 0
End Sub
Private Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer)
unCombo_KeyDown KeyCode
End Sub
Private Sub Combo1_KeyPress(KeyAscii As Integer)
unCombo_KeyPress KeyAscii
End Sub
Private Sub unCombo_KeyDown(KeyCode As Integer)
If KeyCode = vbKeyDelete Then
Combo1Borrado = True
Else
Combo1Borrado = False
End If
End Sub
Private Sub unCombo_KeyPress(KeyAscii As Integer)
'si se pulsa Borrar... ignorar la búsqueda al cambiar
If KeyAscii = vbKeyBack Then
Combo1Borrado = True
Else
Combo1Borrado = False
End If
End Sub
Private Sub unCombo_Change(ByVal sText As String, elCombo As ComboBox)
Dim i As Integer, L As Integer
If Not Combo1Borrado Then
L = Len(sText)
With elCombo
For i = 0 To .ListCount - 1
If StrComp(sText, Left$(.List(i), L), 1) = 0 Then
.ListIndex = i
.Text = .List(.ListIndex)
.SelStart = L
.SelLength = Len(.Text) - .SelStart
Exit For
End If
Next
End With
End If
End Sub
Private Sub Form_Load()
Combo1.AddItem "Carlos"
Combo1.AddItem "Jorge"
Combo1.AddItem "Miguel"
Combo1.AddItem "Javier"
Combo1.AddItem "Marta"
Combo1.AddItem "Pedro"
Combo1.AddItem "Abel"
Combo1.AddItem "Fernando"
Combo1.AddItem "Rafa"
Combo1.AddItem "Jose carlos"
End Sub
salu2
sdemingo
pd. el código no es mÃo, es de Carlos y lo expuso en este foro hace tiempo.
