Option buttons actif dans frame

  • Initiateur de la discussion Initiateur de la discussion adinnn
  • Date de début Date de début

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

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:
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
@+
 
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
@+
 
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
 
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
 
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
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Retour