Microsoft 365 forcer REMPLISSAGE Combobox Userform

eric72

XLDnaute Accro
Bonjour à tous,
J'espère que tout le monde va bien, me revoilà pour un petit souci de conditions d'obligation de remplissage de Combobox.
J'ai un Userform, quand je clique sur l'optionbutton "Tournant", s'affiche une combobox ou on sélectionne un nombre de semaines qui déclenche l'affichage de 2, 3,4,5 ou 6 autres combobox que l'on doit remplir obligatoirement, j'ai donc mis ceci:
VB:
    If ObRotation.Value = True And CDbl(CbNbSemRotation.Value) = 2 And CbSemType1.Value = "" Or CbSemType2.Value = "" Then MsgBox "Vous devez sélectionner 2 Semaines type": Exit Sub
    If ObRotation.Value = True And CDbl(CbNbSemRotation.Value) = 3 And CbSemType1 = "" Or CbSemType2 = "" Or CbSemType3 = "" Then MsgBox "Vous devez sélectionner 3 Semaines type": Exit Sub
    If ObRotation.Value = True And CDbl(CbNbSemRotation.Value) = 4 And CbSemType1 = "" Or CbSemType2 = "" Or CbSemType3 = "" Or CbSemType4 = "" Then MsgBox "Vous devez sélectionner 4 Semaines type": Exit Sub
    If ObRotation.Value = True And CDbl(CbNbSemRotation.Value) = 5 And CbSemType1 = "" Or CbSemType2 = "" Or CbSemType3 = "" Or CbSemType4 = "" Or CbSemType5 = "" Then MsgBox "Vous devez sélectionner 5 Semaines type": Exit Sub
    If ObRotation.Value = True And CDbl(CbNbSemRotation.Value) = 6 And CbSemType1 = "" Or CbSemType2 = "" Or CbSemType3 = "" Or CbSemType4 = "" Or CbSemType5 = "" Or CbSemType6 = "" Then MsgBox "Vous devez sélectionner 6 Semaines type": Exit Sub

Je ne sais pas ou est(sont) la(les) boulette(s), mais rien ne fonctionne, j'ai essayé pleins d'astuces et rien ne va, quelqu'un aurait-il une petite idée car là je cale!!!
Merci beaucoup à tous.
Eric
 

Pièces jointes

  • test.xlsm
    98.9 KB · Affichages: 8
Solution
Bonsoir le Fil
une autre possibilité
VB:
 If TxtDateRotation = "" And ObRotation = True Then MsgBox "Vous devez Sélectionner une date de début ": Exit Sub
    If TxtDateFixe = "" And ObFixe = True Then MsgBox "Vous devez Sélectionner une date de début ": Exit Sub
    If ChbMajoration = True And TxtTaux = "" Then MsgBox "Vous devez saisir un taux de Majoration": TxtTaux.SetFocus: Exit Sub
    If ObFixe.Value = False And ObRotation.Value = False Then MsgBox "Vous devez choisir si le planning est fixe ou tournant": Exit Sub
    If ObFixe.Value = True And CbSemTypeFixe = "" Then MsgBox "Vous avez choisi un Planning fixe, vous devez sélectionner la Semaine Type attribuée": CbSemTypeFixe.SetFocus: Exit Sub

Select Case ObRotation.Value 'ça...

TooFatBoy

XLDnaute Barbatruc
Bonjour,

Une proposition :
VB:
Dim CestOK as Boolean

    If ObRotation.Value = True Then
        If CbNbSemRotation.Value = "" Then MsgBox "Vous avez choisi un Planning à rotation, vous devez sélectionner le nombre de semaines de rotation": CbNbSemRotation.SetFocus: Exit Sub
        CestOK = True
        If CDbl(CbNbSemRotation.Value) = 2 And CbSemType1.Value = "" Or CbSemType2.Value = "" Then CestOK = False
        If CDbl(CbNbSemRotation.Value) = 3 And CbSemType3 = "" Then CestOK = False
        If CDbl(CbNbSemRotation.Value) = 4 And CbSemType4 = "" Then CestOK = False
        If CDbl(CbNbSemRotation.Value) = 5 And CbSemType5 = "" Then CestOK = False
        If CDbl(CbNbSemRotation.Value) = 6 And CbSemType6 = "" Then CestOK = False
        If CestOK = False Then MsgBox "Vous devez sélectionner " & CbNbSemRotation.Value & " Semaines type": Exit Sub
    End If
 

Oneida

XLDnaute Impliqué
Re,
Le probleme est que meme non visible les comboboxs sont testees dans le code.
Donc, une facon de faire
VB:
    If ObRotation.Value = True And CDbl(CbNbSemRotation.Value) = 2 Then
        If CbSemType1.Value = "" Or CbSemType2.Value = "" Then
            MsgBox "Vous devez sélectionner 2 Semaines type": Exit Sub
        End If
    ElseIf ObRotation.Value = True And CDbl(CbNbSemRotation.Value) = 3 Then
        If CbSemType1 = "" Or CbSemType2 = "" Or CbSemType3 = "" Then
            MsgBox "Vous devez sélectionner 3 Semaines type": Exit Sub
        End If
    ElseIf ObRotation.Value = True And CDbl(CbNbSemRotation.Value) = 4 Then
    'etc, etc
 

eric72

XLDnaute Accro
Bonjour,

Une proposition :
VB:
Dim CestOK as Boolean

    If ObRotation.Value = True Then
        If CbNbSemRotation.Value = "" Then MsgBox "Vous avez choisi un Planning à rotation, vous devez sélectionner le nombre de semaines de rotation": CbNbSemRotation.SetFocus: Exit Sub
        CestOK = True
        If CDbl(CbNbSemRotation.Value) = 2 And CbSemType1.Value = "" Or CbSemType2.Value = "" Then CestOK = False
        If CDbl(CbNbSemRotation.Value) = 3 And CbSemType3 = "" Then CestOK = False
        If CDbl(CbNbSemRotation.Value) = 4 And CbSemType4 = "" Then CestOK = False
        If CDbl(CbNbSemRotation.Value) = 5 And CbSemType5 = "" Then CestOK = False
        If CDbl(CbNbSemRotation.Value) = 6 And CbSemType6 = "" Then CestOK = False
        If CestOK = False Then MsgBox "Vous devez sélectionner " & CbNbSemRotation.Value & " Semaines type": Exit Sub
    End If
Hello,
Je regarde ça dès demain
Merciiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
 

ChTi160

XLDnaute Barbatruc
Bonsoir le Fil
une autre possibilité
VB:
 If TxtDateRotation = "" And ObRotation = True Then MsgBox "Vous devez Sélectionner une date de début ": Exit Sub
    If TxtDateFixe = "" And ObFixe = True Then MsgBox "Vous devez Sélectionner une date de début ": Exit Sub
    If ChbMajoration = True And TxtTaux = "" Then MsgBox "Vous devez saisir un taux de Majoration": TxtTaux.SetFocus: Exit Sub
    If ObFixe.Value = False And ObRotation.Value = False Then MsgBox "Vous devez choisir si le planning est fixe ou tournant": Exit Sub
    If ObFixe.Value = True And CbSemTypeFixe = "" Then MsgBox "Vous avez choisi un Planning fixe, vous devez sélectionner la Semaine Type attribuée": CbSemTypeFixe.SetFocus: Exit Sub

Select Case ObRotation.Value 'ça commence Ici
     Case True And CbNbSemRotation.Value = ""
         MsgBox "Vous avez choisi un Planning à rotation, vous devez sélectionner le nombre de semaines de rotation": CbNbSemRotation.SetFocus: Exit Sub
     Case True And CDbl(CbNbSemRotation.Value) = 2
          If CbSemType1.Value = "" Or CbSemType2.Value = "" Then MsgBox "Vous devez sélectionner 2 Semaines type": Exit Sub
     Case True And CDbl(CbNbSemRotation.Value) = 3
          If CbSemType1 = "" Or CbSemType2 = "" Or CbSemType3 = "" Then MsgBox "Vous devez sélectionner 3 Semaines type": Exit Sub
     Case True And CDbl(CbNbSemRotation.Value) = 4
          If CbSemType1 = "" Or CbSemType2 = "" Or CbSemType3 = "" Or CbSemType4 = "" Then MsgBox "Vous devez sélectionner 4 Semaines type": Exit Sub
     Case True And CDbl(CbNbSemRotation.Value) = 5
          If CbSemType1 = "" Or CbSemType2 = "" Or CbSemType3 = "" Or CbSemType4 = "" Or CbSemType5 = "" Then MsgBox "Vous devez sélectionner 5 Semaines type": Exit Sub
     Case True And CDbl(CbNbSemRotation.Value) = 6
          If CbSemType1 = "" Or CbSemType2 = "" Or CbSemType3 = "" Or CbSemType4 = "" Or CbSemType5 = "" Or CbSemType6 = "" Then MsgBox "Vous devez sélectionner 6 Semaines type": Exit Sub
End Select 'Fin du test
With [TbEffectif].ListObject
Jean marie
 

ChTi160

XLDnaute Barbatruc
Re
une autre version Perfectible
Code:
Dim NbrRotation As Byte
''''''''''''''''''
''''''''''''''
If ObRotation.Value Then
   NbrRotation = IIf(CbNbSemRotation.Value = "", 0, CbNbSemRotation.Value)
  If NbrRotation = 0 Then MsgBox "Vous avez choisi un Planning à rotation, vous devez sélectionner le nombre de semaines de rotation": CbNbSemRotation.SetFocus: Exit Sub
For i = 1 To NbrRotation
    If Me.Controls("CbSemType" & i).Text = Empty Then MsgBox "Vous devez sélectionner " & NbrRotation & " Semaines type": Exit Sub
Next
End If
Jean marie
 

eric72

XLDnaute Accro
Re
une autre version Perfectible
Code:
Dim NbrRotation As Byte
''''''''''''''''''
''''''''''''''
If ObRotation.Value Then
   NbrRotation = IIf(CbNbSemRotation.Value = "", 0, CbNbSemRotation.Value)
  If NbrRotation = 0 Then MsgBox "Vous avez choisi un Planning à rotation, vous devez sélectionner le nombre de semaines de rotation": CbNbSemRotation.SetFocus: Exit Sub
For i = 1 To NbrRotation
    If Me.Controls("CbSemType" & i).Text = Empty Then MsgBox "Vous devez sélectionner " & NbrRotation & " Semaines type": Exit Sub
Next
End If
Jean marie
Bonjour Jean-Marie,
Ta proposition est géniale, pourquoi faire compliqué quand on peut faire simple!!!
Merci beaucoup et bonne journée.
Prends soin de toi
Eric
 

eric72

XLDnaute Accro
Bonjour,

Une proposition :
VB:
Dim CestOK as Boolean

    If ObRotation.Value = True Then
        If CbNbSemRotation.Value = "" Then MsgBox "Vous avez choisi un Planning à rotation, vous devez sélectionner le nombre de semaines de rotation": CbNbSemRotation.SetFocus: Exit Sub
        CestOK = True
        If CDbl(CbNbSemRotation.Value) = 2 And CbSemType1.Value = "" Or CbSemType2.Value = "" Then CestOK = False
        If CDbl(CbNbSemRotation.Value) = 3 And CbSemType3 = "" Then CestOK = False
        If CDbl(CbNbSemRotation.Value) = 4 And CbSemType4 = "" Then CestOK = False
        If CDbl(CbNbSemRotation.Value) = 5 And CbSemType5 = "" Then CestOK = False
        If CDbl(CbNbSemRotation.Value) = 6 And CbSemType6 = "" Then CestOK = False
        If CestOK = False Then MsgBox "Vous devez sélectionner " & CbNbSemRotation.Value & " Semaines type": Exit Sub
    End If
Bonjour,

Efficace comme d'habitude, les deux méthodes (avec celle de Jean-Marie) sont au top.
Bonne journée
Eric
 

eric72

XLDnaute Accro
Re,
Le probleme est que meme non visible les comboboxs sont testees dans le code.
Donc, une facon de faire
VB:
    If ObRotation.Value = True And CDbl(CbNbSemRotation.Value) = 2 Then
        If CbSemType1.Value = "" Or CbSemType2.Value = "" Then
            MsgBox "Vous devez sélectionner 2 Semaines type": Exit Sub
        End If
    ElseIf ObRotation.Value = True And CDbl(CbNbSemRotation.Value) = 3 Then
        If CbSemType1 = "" Or CbSemType2 = "" Or CbSemType3 = "" Then
            MsgBox "Vous devez sélectionner 3 Semaines type": Exit Sub
        End If
    ElseIf ObRotation.Value = True And CDbl(CbNbSemRotation.Value) = 4 Then
    'etc, etc
Bonjour,
Merci pour cette proposition
Bonne journée
Eric
 

ChTi160

XLDnaute Barbatruc
Bonjour lEric,le Fil
Une question : dans le fichier de Toofatboy
Le fait de tester le dernier élément du nombre de rotation ex 3 rotations choisies permet de ne sélectionner que deux ex 1 et 3 ,2 et 3
3 n'étant pas vide , c'est considéré comme ok .
Est une mauvaise interprétation de ma part ?
Bonne journée
Jean marie
 

Statistiques des forums

Discussions
312 219
Messages
2 086 372
Membres
103 198
dernier inscrit
CACCIATORE