RE:Desplegar DBcombo segun escribo
hola sergio esto lo sague de la pagina del Guille
agrega un combo1
metele datos
escribe esto
==================
en un modulo
==================
#If Win32 Then
Declare Function SendMessage Lib "User32" Alias "SendMessageA" _
(ByVal hWnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long
#Else
Declare Function SendMessage Lib "User" _
(ByVal hWnd As Integer, ByVal wMsg As Integer, _
ByVal wParam As Integer, lParam As Any) As Long
#End If
==================
en un form
==================
Const CB_FINDSTRINGEXACT = &H158 'Buscar cadena completa en un ComboBox
Const LB_FINDSTRINGEXACT = &H1A2 'Buscar cadena completa en un ListBox
Const CB_FINDSTRING = &H14C 'Buscar cadena desde el principio en un ComboBox
Const LB_FINDSTRING = &H18F
Private Sub Combo1_KeyPress(KeyAscii As Integer)
Dim CB As Long
Dim FindString As String
Const CB_ERR = (-1)
Const CB_FINDSTRING = &H14C
If KeyAscii < 32 Or KeyAscii > 127 Then Exit Sub
If Combo1.SelLength = 0 Then
FindString = Combo1.Text & Chr$(KeyAscii)
Else
FindString = Left$(Combo1.Text, Combo1.SelStart) & Chr$(KeyAscii)
End If
CB = SendMessage(Combo1.hWnd, CB_FINDSTRING, -1, ByVal FindString)
If CB <> CB_ERR Then
Combo1.ListIndex = CB
Combo1.SelStart = Len(FindString)
Combo1.SelLength = Len(Combo1.Text) - Combo1.SelStart
End If
KeyAscii = 0
End Sub
Public Function ActualizarLista(sTexto As String, cList As Control) As Long
'Esta función comprobará si el texto indicado existe en la lista
'Si no es así, lo añadirá
'El valor devuelto, será la posición dentro de la lista ó -1 si hay "fallos"
'
'Para buscar en el List/combo usaremos una llamada al API
'(si ya hay una forma de hacerlo, ¿para que re-hacerla?)
'
Const CB_FINDSTRINGEXACT = &H158 'Mensaje para los combos
Const LB_FINDSTRINGEXACT = &H1A2 'Mensaje para las Listas
Dim L As Long
If cList.ListCount = 0 Then
'Seguro que no está, así que añadirla
L = -1
Else
'Si el control es un Combo
If TypeOf cList Is ComboBox Then
L = SendMessage(cList.hWnd, CB_FINDSTRINGEXACT, -1, ByVal sTexto)
'Si el control es un list
ElseIf TypeOf cList Is ListBox Then
L = SendMessage(cList.hWnd, LB_FINDSTRINGEXACT, -1, ByVal sTexto)
Else
'no es un control List o Combo, salir
ActualizarLista = -1
Exit Function
End If
End If
'Si no está, añadirla
If L = -1 Then
cList.AddItem sTexto
L = ActualizarLista(sTexto, cList)
End If
ActualizarLista = L
End Function