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
| Private Sub UserForm_Initialize()
'Dim i As Integer
'Dim nb As Integer
' nb = consult.ListBox1.ListCount
' For i = 0 To nb
' Me.id_etab.Caption = consult.ListBox1.List(i)
' Next i
'
End Sub
Sub ModifLigneByID(IDLigne As Long)
Dim TheRow As ListRow, aCtrl As Control
'On pointe le tableau structuré
With F_BD.ListObjects("Tab_BD")
'On recherche la ligne contenant l'ID
On Error Resume Next
Set TheRow = .ListRows(WorksheetFunction.Match(IDLigne, .ListColumns("ID").DataBodyRange, 0))
On Error GoTo 0
If TheRow Is Nothing Then
'ID inexistant dans le tableau
'Gestion à faire...
Else
'On procéde à l'affichage
'On boucle sur les controles du userorm
For Each aCtrl In Me.Controls
'On regarde si le tag est renseigné
If aCtrl.Tag <> "" Then
'On va chercher l'info dans therow
'Là il serait bien de gérer le cas ou le tag ne correspond à aucune colonne
aCtrl.value = TheRow.Range(1, .ListColumns(aCtrl.Tag).Index).value
End If
Next
'On affiche le userform
Me.Show
End If
End With
End Sub |