Public Sub LLENAR(SENTENCIA As String, OBJETO As Object) 'PARA CARGAR LISTA EN CASI CUALQUIER COSA
'On Local Error Resume Next
Dim RST As Recordset, N As Integer: Set RST = New Recordset
RST.Open SENTENCIA, DTE.Connection1, adOpenDynamic, adLockReadOnly
Select Case TypeName(OBJETO)
Case "ListBox", "ComboBox"
OBJETO.Clear
If RST.RecordCount > 0 Then
Do While Not RST.EOF
OBJETO.AddItem RTrim(RST.Fields(0).VALUE): RST.MoveNext
Loop
OBJETO.ListIndex = 0
End If
Case "ListView", "IListView"
OBJETO.ListItems.Clear
If RST.RecordCount > 0 Then
Do While Not RST.EOF
N = N + 1 ' para las facturas existe el campo exp que se debe valorar y luego continuar; si no se trata de ese poner el valor sea cual sea
OBJETO.ListItems.Add N, , IIf(RST.Fields(0).Type = 11, IIf(RST.Fields(0).VALUE = 0, "No", "Si"), RTrim(RST.Fields(0).VALUE))
For BUCLE = 1 To RST.Fields.Count - 1
OBJETO.ListItems.Item(N).SubItems(BUCLE) = IIf(RST.Fields(BUCLE).Type = 11, IIf(RST.Fields(BUCLE).VALUE = 0, "No", "Si"), RST.Fields(BUCLE).VALUE)
Next BUCLE
RST.MoveNext
Loop
End If
If OBJETO.ListItems.Count > 0 Then 'Auto seleccionar el primer registro
OBJETO.ListItems(1).Selected = True
End If
Case "LynxComboBox"
OBJETO.Clear
For BUCLE = 1 To RST.RecordCount
OBJETO.AddItem RST.Fields(0)
For N = 1 To RST.Fields.Count - 1
OBJETO.ItemText(OBJETO.NewIndex, N) = IIf(IsNull(RST.Fields(N).VALUE) = True, "", RST.Fields(N).VALUE)
Next N
RST.MoveNext
Next BUCLE
If OBJETO.ListCount > 0 Then
OBJETO.ListIndex = 0
End If
End Select
Set RST = Nothing
End Sub
'Supon que tienes un textbox llamado text1 y un listview denominado LW1
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
DIM SQL as string
SQL = "Select Campo1, campo2, campo3 from tabla1 where CAMPO_BUSQUEDA = '" & text1.text & "'"
CALL LLENAR(SQL, LW1)
End Sub
'OBS: Este es parte de un codigo propio por ende existen comentarios y formatos que te pueden resultar incoherente solo es para que tengas una idea.