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
| Private Sub Construction(ByRef res As Recordset)
'On ferme d'abord le sous formulaire pour pouvoir l'éditer
Me.Choix_sous_formulaire.Visible = False
Me.Choix_sous_formulaire.SourceObject = ""
'On ouvre le formulaire en mode création, sans l'afficher
DoCmd.OpenForm "Profil général - Choix", acDesign, , , acFormPropertySettings, acHidden
'On supprime tous les contrôles qui se trouvent dans le formulaire
Dim i As Integer
For i = 1 To Forms("Profil général - Choix").Controls.Count
DeleteControl "Profil général - Choix", Forms("Profil général - Choix").Controls(0).Name
Next i
'On crée les contrôles adéquats
Dim ctl As Control
Dim Gauche As Integer
Dim Haut As Integer
Set DB = CurrentDb()
Dim rep As Recordset
For i = 1 To NbChoix
'Pour chaque enregistrement de la table Choix, on calcule la position que devront avoir les contrôles associés
Haut = 100 + 300 * (i - 1)
Gauche = 500 * (CInt(res("Rang_choix")) - 1)
'On affiche l'intitulé du choix
Set ctl = CreateControl("Profil général - Choix", acLabel, acDetail, , , 500 + Gauche, Haut, 8000, 300)
With ctl
.Name = "Intitulé_choix_" + Str(i)
.Caption = res("Intitulé_choix")
End With
'On affiche la case à côcher associé
Set ctl = CreateControl("Profil général - Choix", acCheckBox, acDetail, , , 200 + Gauche, Haut, 500, 300)
ctl.Name = "Choisi_" + Str(i)
'Si ce choix a été choisi, on coche la case
Set rep = DB.OpenRecordset("SELECT ID_réponse FROM Réponse WHERE ID_choix =" + Str(res("ID_Choix")) + ";")
If rep.RecordCount > 0 Then
ctl.DefaultValue = True
Else
ctl.DefaultValue = False
End If
res.MoveNext
Next i
'On libère la mémoire
Set ctl = Nothing
rep.Close
'On ferme le formulaire
DoCmd.Close acForm, "Profil général - Choix", acSaveYes
'On réaffiche le sous formulaire
Me.Choix_sous_formulaire.SourceObject = "Profil général - Choix"
Me.Choix_sous_formulaire.Visible = True
End Sub |
Partager