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
| Private Sub Form_Current()
Dim oDB As DAO.Database
Dim oQdf As DAO.QueryDef
Dim oRstActivite As DAO.Recordset, oRstRealiser As DAO.Recordset
Dim Item As ListItem
Dim intAct As Integer
Set oDB = CurrentDb
'Vide la zone de liste
'Dim ListView1 As ListView
ListView1.ListItems.Clear
'Définit la propriété Case à cocher à oui
ListView1.Checkboxes = True
ListView1.View = lvwList
'Prépare la requête sur la table tblRealiser
Set oQdf = oDB.QueryDefs("R02")
With oQdf
.Parameters(0).Value = Me.Numsite
Set oRstRealiser = .OpenRecordset
End With
Set oRstActivite = oDB.OpenRecordset("R01")
'Parcours le recordset des activités
With oRstActivite
While Not .EOF
intAct = .Fields(0)
'Crée la nouvelle ligne
Set Item = ListView1.ListItems.Add(Key:="A" & .Fields(0), Text:=.Fields(1))
'recherche l'enregistrement
With oRstRealiser
.FindFirst "NumActivite=" & intAct
Item.Checked = Not .NoMatch
End With
.MoveNext
Wend
End With
End Sub
Private Sub ListView1_ItemCheck(ByVal Item As Object)
Dim oDB As DAO.Database
Dim oQdf As DAO.QueryDef
Dim strName As String
If Item.Checked Then
strName = "R03"
Else
strName = "R04"
End If
Set oDB = CurrentDb
Set oQdf = oDB.QueryDefs(strName)
With oQdf
.Parameters("PSite") = CInt(Me.Numsite)
.Parameters("PActivite") = CInt(Mid(Item.Key, 2))
.Execute
End With
End Sub |
Partager