1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
Public Sub RemplirListView(strTabloChamps, strNomSrce As Variant, LVperso As Control)
Dim rstLV As Recordset 'Variable de Recordset
Dim strSQL As String 'Variable tableau pour la source de données
Dim lNbEnregistr As Long 'Variable compteur du nombre de lignes
Dim iNbColonne As Integer 'Nombre colonne comptage dans la listView à partir de zéro
Dim iNbLigne As Integer 'Nombre ligne comptage dans la listView à partir de un
Dim vText As Variant ' valeur des différents champs du rst
Dim strSQLtmp As String
Dim strElementTmp As String
Dim i As Integer
On Error GoTo Gestion_Erreur
'Debug.Print "strTabloChamps(0) == " & strTabloChamps(0)
'Construction de l'instruction SQL source de la ListView
For i = LBound(strTabloChamps) To UBound(strTabloChamps)
strSQLtmp = strSQLtmp & " " & IIf(i <> UBound(strTabloChamps), strTabloChamps(i) & "," & " ", strTabloChamps(i))
Next i
strSQL = "select " & strSQLtmp & " from " & strNomSrce
'Debug.Print "strSQLtmp == " & strSQLtmp
'Debug.Print "strSQL == " & strSQL
Set rstLV = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
' Définition des En-Têtes de colonnes (Un par colonne)
rstLV.MoveLast
rstLV.MoveFirst
'Vidange de la ListView
LVperso.ListItems.Clear
LVperso.ColumnHeaders.Clear
For iNbColonne = 0 To rstLV.Fields.Count - 1
LVperso.ColumnHeaders.Add , , rstLV.Fields(iNbColonne).Name, LVperso.Width / rstLV.Fields.Count '1000
'Debug.Print rstLV.Fields(iNbColonne).Name
Next iNbColonne
' Debug.Print "__________________________________________________________"
' ' Définition du nombre d'enregistrements
lNbEnregistr = rstLV.RecordCount
' Apparement, on doit remplir d'abord la première colonne.
For iNbLigne = 1 To lNbEnregistr
vText = Nz(rstLV.Fields(0).Value, "")
LVperso.ListItems.Add iNbLigne, , vText
rstLV.MoveNext
Next iNbLigne
rstLV.MoveFirst
For iNbColonne = 1 To rstLV.Fields.Count - 1
'Debug.Print lNbEnregistr
For iNbLigne = 1 To lNbEnregistr
vText = Nz(rstLV.Fields(iNbColonne).Value, "")
LVperso.ListItems(iNbLigne).ListSubItems.Add iNbColonne, , vText
rstLV.MoveNext
Next iNbLigne
rstLV.MoveFirst
Next iNbColonne
LVperso.View = lvwReport 'Spécifie l'affichage en mode Détails
LVperso.GridLines = True
Sortir:
Exit Sub
Gestion_Erreur:
MsgBox "l'erreur numéro " & Err.Number & " ie : " & Err.Description & " s'est produite !!!"
Resume Sortir
End Sub |
Partager