Sie sind auf Seite 1von 2

Formulario principal

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'' LV = ListView ''
'' cnn = Conector ''
'' rs = Recordset ''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' variables para la conexión y el recordset
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public cnn As New ADODB.Connection
Public rs As New ADODB.Recordset
Public ObjItem As ListItem
Dim i As Integer

Private Sub Form_Load()

'Configuracion del ListView

LV.Arrange = lvwNone
LV.BorderStyle = ccNone
LV.DragMode = vbManual
LV.FlatScrollBar = True
LV.Font = "Verdana"
LV.FullRowSelect = True
LV.GridLines = True
LV.HideSelection = False
LV.LabelEdit = lvwManual
LV.View = lvwReport

With LV
' Agrega dos columnas
.ColumnHeaders.Add , , "ID"
.ColumnHeaders.Add , , "Nombre"
.ColumnHeaders.Add , , "Apellido"
.ColumnHeaders.Add , , "Telefono"
.ColumnHeaders.Add , , "Direccion"
.ColumnHeaders.Add , , "Sexo"
.ColumnHeaders.Add , , "Fecha"
End With

'Abre conexion
With cnn
.CursorLocation = adUseClient
.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\
datos.mdb" & ";Persist Security Info=False"
End With

' Carga Recorset con los datos


rs.Open "select * from Personas", cnn, adOpenStatic, adLockOptimistic

' llena el ListView


Call CargarListView(LV, rs)
La Siguiente función va escrita en un modulo.

Public Sub CargarListView(LV As ListView, rs As ADODB.Recordset)

On Error GoTo ErrorSub

'Limpia el LV
LV.ListItems.Clear

' Si hay registros


If rs.RecordCount > 0 Then

' Recorre el recordset


While Not rs.EOF

' Añade los datos


Set ObjItem = LV.ListItems.Add(, , rs(0))

ObjItem.SubItems(1) = rs!Nombre
ObjItem.SubItems(2) = rs!Apellido
ObjItem.SubItems(3) = rs!Telefono
ObjItem.SubItems(4) = rs!Direccion

If Abs(rs!sexo) = 0 Then
ObjItem.SubItems(5) = "Masculino"
Else
ObjItem.SubItems(5) = "Femenino"
End If
ObjItem.SubItems(6) = rs!FechaDeAlta

' Siguiente registro


rs.MoveNext
Wend

End If
Exit Sub

ErrorSub:
MsgBox ("ERROR")
End Sub

Das könnte Ihnen auch gefallen