Para el que le pueda servir
Private Sub UserForm_Initialize()
Call Conexion 'Creacion de coneccion con base de Datos
- Set Rs = New ADODB.Recordset
- Rs.Open "SELECT * FROM Tecnologia ORDER BY [Articulo]", myConexion, adOpenStatic
'----------------------------------------------------------------------------------------------------------------------------------------- - With ListBox1
.ColumnCount = 5
.ColumnWidths = "50 pt;200 pt;40 pt;70 pt;50 pt"
.ColumnHeads = False 'True
End With
'-------------------------------------------------------------------------------------------------------------------------------------- - Rs.MoveFirst
i = 0
'Lleno el listbox con datos de la Base de Datos - With Me.ListBox1
.Clear
Do
.AddItem
.List(i, 0) = Rs![Codigo]
.List(i, 1) = Rs![Articulo]
.List(i, 2) = Rs![Cantidad]
.List(i, 3) = Rs![PrecioC]
.List(i, 4) = Rs![PrecioV]
i = i + 1
Rs.MoveNext
Loop Until Rs.EOF
End With
Rs.Close
Set Rs = Nothing - End Sub
- Private Sub ListBox1_Click()
- Dim Buscx As String
'Al hacer click en el ListBox - txtCodigo = ListBox1.Column(0)
'------------------------------------------------------------------------------------------------- - Buscx = "[Codigo]=" & txtCodigo
- With Rs
.Open "SELECT * FROM Tecnologia ", myConexion, adOpenKeyset, adLockOptimistic
. Find Buscx 'Busco el registro en la base de datos atraves del codigo y cargo los datos en los textbox
.Fields("Articulo").Value = txtArticulo
.Fields("Cantidad").Value = txtCantidad
.Fields("PrecioC").Value = txtCompra
.Fields("PrecioV").Value = txtVenta
.Close - End With
- Set Rs = Nothing
End Sub