'Se declara estas variables. ;)
Dim CnN As ADODB.Connection
Dim RsT As ADODB.Recordset
'''''''''''''''''''''''''''''''''''''''''''
Dim BD As String
Dim CuentaRegs As Integer
Private Sub Form_Load()
AbreConexion 'SUB PARA ABRIR LA CONEXIÓN
Set RsT = New ADODB.Recordset 'SE ESTABLECE EL REGISTROS
With RsT 'SE ABRE ELREGISTROS
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockReadOnly
.Open "SELECT nombre FROM datos ORDER BY nombre", CnN
End With
For CuentaRegs = 1 To RsT.RecordCount
List1.AddItem RsT.Fields("nombre") 'SE AGREGA UNO POR UNO EL DATO DEL CAMPO NOMBRE
RsT.MoveNext 'SE AVANZA UNO ADELANTE
Next
RsT.Close 'SE CIERRA EL REGISTROS
Set RsT = Nothing 'Y SE DEJA EN NADA
End Sub
Private Sub Form_Unload(Cancel As Integer)
CnN.Close 'SE CIERRA LA CONEXIÓN AL SALIR
Set CnN = Nothing 'SE ESTABLECE
End Sub
Private Sub List1_Click()
Set RsT = New ADODB.Recordset
With RsT 'abre el registro y empieza la consulta
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockReadOnly
.Open "SELECT dato1 FROM datos WHERE nombre=" & _
Chr(39) & List1.Text & Chr(39), CnN
End With
Label1.Caption = RsT.Fields("dato1") 'EL CAMPO DATO1 EN EL LABEL
RsT.Close 'SE CIERRA
Set RsT = Nothing 'se reconoce
End Sub
Sub AbreConexion()
BD = App.Path & "\" & "Almaceamiento.mdb" 'RUTA BASE DE DATOS
Set CnN = New ADODB.Connection 'SE ESTABLECE UNA CONEXIÓN
With CnN
.CursorLocation = adUseClient
.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & BD
End With
End Sub