VERSION 5.00
Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} Questions 
   Caption         =   "Ajout ou modification de question"
   ClientHeight    =   13575
   ClientLeft      =   45
   ClientTop       =   390
   ClientWidth     =   14370
   OleObjectBlob   =   "Questions.frx":0000
   StartUpPosition =   1  'CenterOwner
End
Attribute VB_Name = "Questions"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Public Cel_Trouvée As Range

Private Sub CommandButton1_Click() ' validation

On Error GoTo fin
    Dim Der_Ligne As Long, Cpt As Integer
    If Test_Validation = False Then Exit Sub
    Application.ScreenUpdating = False

    With Sheets(FeuilleJeu)
        If TextBox7 <> "" Then 'Numéro de la question ou fiche
            For Cpt = 1 To 5
                .Cells(Cel_Trouvée.Row, Cpt).Value = Controls("TextBox" & Cpt).Value
            Next Cpt
            .Cells(Cel_Trouvée.Row, 6).Value = ""
             
            If TextBox6.Value <> "" Then
                .Cells(Cel_Trouvée.Row, 7).Value = TextBox6.Value
            Else
                .Cells(Cel_Trouvée.Row, 7).Value = 20
            End If
        Else
        
            Der_Ligne = .Range("A" & Rows.Count).End(xlUp).Row
            For Cpt = 1 To 7 '5
                .Cells(Der_Ligne + 1, Cpt).Value = Controls("TextBox" & Cpt).Value
            Next Cpt
            
            .Cells(Der_Ligne + 1, 6).Value = ""
            If TextBox6.Value <> "" Then
                .Cells(Der_Ligne + 1, 7).Value = TextBox6.Value '7
           Else
                .Cells(Der_Ligne + 1, 7).Value = 20 '7
            End If
                       
     '------------------------------
     
             If TextBox8.Value <> "" Then
                 .Cells(Der_Ligne + 1, 15).Value = TextBox8.Value 'O
                End If
            If TextBox9.Value <> "" Then
               .Cells(Der_Ligne + 1, 16).Value = TextBox9.Value 'p
                End If
    '-----------------------------
    
            .Cells(Der_Ligne + 1, 8).Value = Der_Ligne '8
            Range("A" & Der_Ligne & ":H" & Der_Ligne).Select 'H
            Selection.Copy
            Range("A" & Der_Ligne + 1).Select
            Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
                SkipBlanks:=False, Transpose:=False
        End If
    End With
    Application.ScreenUpdating = True
    For Cpt = 1 To 9 '7
        Controls("TextBox" & Cpt) = ""
    Next Cpt
    TextBox1.SetFocus
    Application.DisplayAlerts = False
        On Error Resume Next
            ThisWorkbook.Save
        On Error GoTo 0
    Application.DisplayAlerts = True
    
    
fin:
    If Err.Number <> 0 Then MsgBox "Erreur " & Err.Number & vbLf & Err.Description

End Sub

Private Function Test_Validation() ' on test s'il y a bien 5 textbox qui sont remplies
    Dim Cpt As Integer
    Test_Validation = True
    For Cpt = 1 To 5
        If Controls("TextBox" & Cpt).Value = "" Then
            Test_Validation = False
            Exit For
        End If
    Next Cpt
End Function

Private Sub CommandButton2_Click() ' Annuler / Quitter
    Dim Cpt As Integer
    For Cpt = 1 To 9 '7--------------------
        Controls("TextBox" & Cpt) = ""
    Next Cpt
    Unload Me
    Application.DisplayAlerts = False
        On Error Resume Next
            ThisWorkbook.Save
        On Error GoTo 0
    Application.DisplayAlerts = True
End Sub

Private Sub CommandButton3_Click() ' Effacer tout
    Dim Cpt As Integer
    For Cpt = 1 To 9 '7--------------------
        Controls("TextBox" & Cpt) = ""
    Next Cpt
    TextBox1.SetFocus
End Sub

Private Sub CommandButton4_Click() ' recherche une question
    If TextBox7.Value <> "" Then
        Call AfficheQuestion
    End If
End Sub

Private Sub SpinButton1_Change()
    On Error Resume Next
    If IsNumeric(CDbl(TextBox7.Value)) Then
        If CDbl(TextBox.Value) > 0 And CDbl(TextBox7.Value) < Sheets(FeuilleJeu).Range("H" & Rows.Count).End(xlUp).Row Then Call AfficheQuestion 'H
    End If
End Sub

Private Sub SpinButton1_SpinDown()
    On Error Resume Next
    If CDbl(TextBox7.Value) - 1 < 1 Then
        TextBox7.Value = Sheets(FeuilleJeu).Range("H" & Rows.Count).End(xlUp).Row - 1 'H
    Else
        TextBox7.Value = CDbl(TextBox7.Value) - 1
    End If
    Call AfficheQuestion
End Sub

Private Sub SpinButton1_SpinUp()
    On Error Resume Next
    If CDbl(TextBox7.Value) + 1 > Sheets(FeuilleJeu).Range("H" & Rows.Count).End(xlUp).Row - 1 Then 'H
        TextBox7.Value = 1
    Else
        TextBox7.Value = CDbl(TextBox7.Value) + 1
    End If
    Call AfficheQuestion
End Sub

Private Sub TextBox7_Change()
    Dim Cpt As Integer
    If TextBox7.Value = "" Then
        For Cpt = 1 To 9 '7 ------------
            Controls("TextBox" & Cpt) = ""
        Next Cpt
    End If
End Sub

Private Sub UserForm_Initialize()
    TextBox7.Value = 1
    Call AfficheQuestion
End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
    Dim Cpt As Integer
    For Cpt = 1 To 9 '7-------------
        Controls("TextBox" & Cpt) = ""
    Next Cpt
    Application.DisplayAlerts = False
        On Error Resume Next
            ThisWorkbook.Save
        On Error GoTo 0
    Application.DisplayAlerts = True
End Sub

Sub AfficheQuestion()
    Dim Cpt As Integer
    For Cpt = 1 To 6
        Controls("TextBox" & Cpt) = ""
    Next Cpt
    Dim Valeur_Cherchée As Integer
    Dim Plage_de_recherche As Range
    Valeur_Cherchée = CDbl(TextBox7.Value)
    Set Plage_de_recherche = Sheets(FeuilleJeu).Range("H2:H" & Sheets(FeuilleJeu).Range("H" & Rows.Count).End(xlUp).Row)
    Set Cel_Trouvée = Plage_de_recherche.Find(what:=Valeur_Cherchée, LookAt:=xlWhole)
    If Cel_Trouvée Is Nothing Then
        TextBox7.SetFocus
    Else
        For Cpt = 1 To 5
            Controls("TextBox" & Cpt) = Sheets(FeuilleJeu).Cells(Cel_Trouvée.Row, Cpt).Value
        Next Cpt
        TextBox6 = Sheets(FeuilleJeu).Cells(Cel_Trouvée.Row, 7).Value
'---------------------------
         TextBox8 = Sheets(FeuilleJeu).Cells(Cel_Trouvée.Row, 15).Value
          TextBox9 = Sheets(FeuilleJeu).Cells(Cel_Trouvée.Row, 16).Value
'-----------------------------------
          TextBox1.SetFocus
    End If
End Sub
