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
| Public Sub CreerBoutonCode2(NomForm As String)
Dim ctl As Control
Dim NbLignes As Integer
Dim DebLignes As Integer
'ouverture du formulaire en mode création
DoCmd.OpenForm NomForm, acDesign, , , , acHidden
NbLignes = 4
DebLignes = 3
'On supprimer l'ancien code car sinon il y a un problème d'ambiguité des noms
If GetProc(NomForm, "Enregistrer" & "_Click", DebLignes, NbLignes) = True Then
MsgBox "huhu"
DelProc NomForm, DebLignes, NbLignes
End If
'Crée un contrôle "Groupe d'options" :
Set ctl = CreateControl(NomForm, acCommandButton, , "", "", 800, 7000, 2700, 1000) ' 2700 + NombrePartie * 500, 2700, 1000)
With ctl
'Définit un nom pour le contrôle
.Name = "Enregistrer"
.OnClick = "[Event Procedure]"
.Caption = "Enregistrer réponses"
End With
'création du code à éxécuter sur Click du bouton :
Dim mdl As Module
Dim lng As Long 'Sert à récupérer le numéro de la ligne d'insertion de la procédure
Set mdl = Forms(NomForm).Module
lng = mdl.CreateEventProc("Click", "Enregister")
mdl.InsertLines lng + 1, _
vbTab & "Call Test()"
'On libère mémoire allouée aux variables.
Set ctl = Nothing
Set mdl = Nothing
DoCmd.Save acForm, NomForm
'on ferme le formulaire
DoCmd.Close acForm, NomForm
'on le rouvre en mode 'normal'
DoCmd.OpenForm NomForm
End Sub |
Partager