Bonjour,

j'ai une classe avec plusieur "withevents" quand
dans mon userform je met par exemple:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
dim cl as classe1
set cl.opt = me.optionbutton1
 
la tout va bien meme avec un tableau et for next cela marche
mais si je met :
i=1
for each control in me.controls
    if typeof control is msforms.optionbutton then
          set cl(i).opt=control
          i=i+1
     end if
next
la j'ai une erreur (n° 459) l'objet ou la classe ne gere pas le jeu d'evenement

voila la classe :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
72
73
74
75
76
77
78
79
80
81
82
83
Private numQ As Integer
Private numpoids As Integer
Private numvaleur As Integer
Public WithEvents chq As MSForms.CheckBox
Public WithEvents optoui As MSForms.OptionButton
Public WithEvents optnon As MSForms.OptionButton
Private groupe As Collection
Private temppoids
Property Let NUMERO(nmQ As Integer)
numQ = nmQ
End Property
Property Get NUMERO() As Integer
NUMERO = numQ
End Property
Property Let poids(nmpoids As Integer)
numpoids = nmpoids
 
End Property
Property Get poids() As Integer
poids = numpoids
temppoids = numpoids
End Property
Property Get valeur() As Integer
valeur = numvaleur
End Property
Private Sub chq_Click()
If chq.Value = True Then
Me.poids = 0
numvaleur = 0
With Me.optnon
.Value = False
.Enabled = False
End With
With Me.optoui
.Value = False
.Enabled = False
End With
Else
Me.poids = temppoids
Me.optnon.Enabled = True
Me.optoui.Enabled = True
End If
 
End Sub
Property Get Count() As Long
   Count = groupe.Count
End Property
Public Sub Remove(ByVal Index As Variant)
    groupe.Remove (Index)
End Function
Public Function Item(ByVal Index As Variant) As question
    Set Item = groupe.Item(Index)
End Function
Public Sub add(ByRef gg As question, Optional ByVal key As String = "")
groupe.add gg, key
End Sub
Private Sub Class_Initialize()
Set groupe = New Collection
End Sub
Private Sub Class_Terminate()
 If Not (groupe Is Nothing) Then Set groupe = Nothing
End Sub
Private Sub optnon_Click()
If optnon.Value = True Then
numvaleur = 0
End If
End Sub
Private Sub optoui_Click()
If optoui.Value = True Then
numvaleur = Me.poids
End If
End Sub
 
Public Function Createquestion(Nomd As Integer, mpoids As Integer) As question
Dim q As question
    Set q = New question
    With q
        .NUMERO = Nomd
        .poids = mpoids
    End With
    Set Createquestion = q
    If Not (q Is Nothing) Then Set q = Nothing
End Function
et l'evement initialize du userform :


Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
Private Sub UserForm_Initialize()
 
 
 
Set Eval_Question = New question
i = 1
    For Each ctrl In Me.Controls
        If TypeOf ctrl Is MSForms.CheckBox Then
                If Len(Me(ctrl.GroupName)) > 3 Then
                    poid_Q = Right(Me("" & ctrl.GroupName & ""), 2)
                Else
                    poid_Q = Right(Me("" & ctrl.GroupName & ""), 1)
                End If
                i = i + 1
 
        Eval_Question.add Eval_Question.Createquestion(i, CInt(poid_Q)), "" & ctrl.GroupName & ""
                Set Eval_Question.Item("" & ctrl.GroupName & "").chq = ctrl
                End If
    Next
    For Each ctrl In Me.Controls
        If TypeOf ctrl Is MSForms.OptionButton Then
                If ctrl.Caption = "OUI" Then
                    Set Eval_Question.Item("" & ctrl.GroupName & "").optoui = ctrl
                Else
                    Set Eval_Question.Item("" & ctrl.GroupName & "").optnon = ctrl
                End If
        End If
    Next
 
  With ListView1
        With .ColumnHeaders
            .Clear
            .add , , "NOM", 100
            .add , , "PRENOM", 100, lvwColumnLeft
            .add , , "TEL", 50, lvwColumnCenter
      End With
    .View = lvwReport
    .Gridlines = True
    .FullRowSelect = True
    End With
 
End Sub
merci de votre aide