Option buttons actif dans frame

adinnn

XLDnaute Occasionnel
Bonjour à Tous,

je souhaite valider si au moins 1 optionbutton est actif dans chacun des frames d'un userform.

Pour être plus explicite, j'ai dans un userform une dizaine de frames qui regroupent 2 -3 et parfois quatre optionbutton. Je souhaite qu'un message apparaisse(msgbox) lorsque l'utilisateur n'a pas sélectionné d'option dans le userform.

Comment puis-je faire sans trop de code?

Merci
 
Dernière édition:

Pierrot93

XLDnaute Barbatruc
Re : Option buttons actif dans frame

Bonjour,

regarde peut être ceci :
Code:
Option Explicit
Private Sub CommandButton1_Click()
Dim f As Control, c As Control, b As Boolean
For Each f In Me.Controls
    If TypeName(f) = "Frame" Then
        b = False
        For Each c In f.Controls
            If TypeName(c) = "OptionButton" Then
                If c Then b = True: Exit For
            End If
        Next c
        If Not b Then MsgBox "Aucun choix, Frame : " & f.Name
    End If
Next f
End Sub

sans plus de détails, sans doute devras tu adapter...

bonne journée
@+
 

Pierrot93

XLDnaute Barbatruc
Re : Option buttons actif dans frame

Bonjour,

teste la propriété "name" ou la propriété "caption" de la "frame" :
Code:
Option Explicit
Private Sub CommandButton1_Click()
Dim f As Control, c As Control, b As Boolean
For Each f In Me.Controls
    If TypeName(f) = "Frame" Then
        If f.Name <> "Frame3" And f.Name <> "Frame4" Then
        'If f.Caption <> "Frame3" And f.Caption <> "Frame4" Then
            b = False
            For Each c In f.Controls
                If TypeName(c) = "OptionButton" Then
                    If c Then b = True: Exit For
                End If
            Next c
            If Not b Then MsgBox "Aucun choix, Frame : " & f.Name
        End If
    End If
Next f
End Sub

bonne journée
@+
 

Pierrot93

XLDnaute Barbatruc
Re : Option buttons actif dans frame

Re,

en regroupant les 2 tests :
Code:
Option Explicit
Private Sub CommandButton1_Click()
Dim f As Control, c As Control, b As Boolean
For Each f In Me.Controls
    If TypeName(f) = "Frame" And f.Name <> "Frame3" And f.Name <> "Frame4" Then
    'If TypeName(f) = "Frame" And f.Caption <> "Frame3" And f.Caption <> "Frame4" Then
        b = False
        For Each c In f.Controls
            If TypeName(c) = "OptionButton" Then
                If c Then b = True: Exit For
            End If
        Next c
        If Not b Then MsgBox "Aucun choix, Frame : " & f.Name
    End If
Next f
End Sub
 

adinnn

XLDnaute Occasionnel
Re : Option buttons actif dans frame

Bonjour à tous,
je ne suis pas certains de comprendre ce code... Je veux que lorsque tous les frames sont validés(check OK) j'exécute une action spécifique comme exporter en .pdf. Bref je veux faire apparaitre le msgbox tant que tout n'est pas coché. Ensuite j'exécute le code suivant. Si je les mets un après l'autre, il vérifie mais enregistre tout de même.

Code:
Dim f As Control, c As Control, b As Boolean
For Each f In UserFormQAHPB.Controls
    If TypeName(f) = "Frame" Then
        b = False
        For Each c In f.Controls
            If TypeName(c) = "OptionButton" Or TypeName(c) = "CheckBox" Then
                If c Then b = True: Exit For
            End If
        Next c
        If Not b Then MsgBox "Veuillez vérifier le(s) champ(s)!"

    End If
Next f

Code:
  Worksheets("QA - HPBFULL").Activate
 ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
        "C:\Users\maisonmoi\SkyDrive\RMA Checklists\Checklist " & UserFormQAHPB.TextBox1.Text & " - " & UserFormQAHPB.TextBox2.Text & ".pdf" _
        , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
        :=False, OpenAfterPublish:=False
 MsgBox "Enregistrement effectué avec Succès!"
 Unload UserFormQAHPB
 

Misange

XLDnaute Barbatruc
Re : Option buttons actif dans frame

Bonjour
suite à ton autre fil, une proposition

Code:
Dim f As Control, c As Control, b as boolean
dim Nb as Integer
dim nbcoché as integer
For Each f In UserFormQAHPB.Controls
    If TypeName(f) = "Frame" Then
        Nb=nb+1
        For Each c In f.Controls
            If TypeName(c) = "OptionButton" Or TypeName(c) = "CheckBox" Then
                If c Then 
                   b = True
                   nbcoché=nbcoché+1
                   Exit For
                End if
            End If
        Next c
        If Not b Then MsgBox "Veuillez vérifier le(s) champ(s)!"
    End If
Next f
if nbcoché = nb then
'ici ton code de pdf
else
msgbox "Vérifiez"
end if
 

Discussions similaires

Statistiques des forums

Discussions
312 329
Messages
2 087 327
Membres
103 517
dernier inscrit
hbenaoun63