| 12
 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
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 
 | Option Explicit
 
Public Cancelled As Boolean
 
Dim rgData As Range
Dim vaData As Variant
 
 
--------------------------------------------------------------
 
'Données du tableau vers le formulaire
Private Sub LoadRecord()
 
vaData = rgData.Value
 
txDésignation.Value = vaData(1, 1)
 
txNuméro.Value = vaData(1, 3)
 
Select Case vaData(1, 4)
    Case "M"
    opMoteurM.Value = True
    Case "F"
    opMoteurF.Value = True
    Case "G"
    opMoteurG.Value = True
End Select
 
Select Case vaData(1, 12)
    Case "E"
    opProvenanceExterne.Value = True
    Case "I"
    opProvenanceInterne.Value = True
End Select
 
cbFournisseur.Value = vaData(1, 11)
 
cbEmplacement.Value = vaData(1, 2)
 
cbResponsable.Value = vaData(1, 5)
 
cbSpécificité.Value = vaData(1, 19)
 
txCommentaire.Value = vaData(1, 18)
 
txQuantitéMisEnIndisponible.Value = vaData(1, 6)
 
txQuantitéObjectif.Value = vaData(1, 10)
 
txPrixUnitaire.Value = vaData(1, 13)
 
End Sub
 
--------------------------------------------------------------
 
'Données du formulaire vers le tableau
Private Sub SaveRecord()
 
vaData(1, 1) = txDésignation.Value
 
vaData(1, 3) = txNuméro.Value
 
Select Case True
    Case opMoteurM.Value
    vaData(1, 4) = "M"
    Case opMoteurF.Value
    vaData(1, 4) = "F"
    Case opMoteurG.Value
    vaData(1, 4) = "G"
End Select
 
Select Case True
    Case opProvenanceExterne.Value
    vaData(1, 12) = "E"
    Case opProvenanceInterne.Value
    vaData(1, 12) = "I"
End Select
 
vaData(1, 11) = cbFournisseur.Value
 
vaData(1, 2) = cbEmplacement.Value
 
vaData(1, 5) = cbResponsable.Value
 
vaData(1, 19) = cbSpécificité.Value
 
vaData(1, 18) = txCommentaire.Value
 
vaData(1, 6) = txQuantitéMisEnIndisponible.Value
 
vaData(1, 10) = txQuantitéObjectif.Value
 
vaData(1, 13) = txPrixUnitaire.Value
 
rgData.Value = vaData
End Sub
 
 
--------------------------------------------------------------
 
Private Sub sbNavigator_Change()
Call SaveRecord
Set rgData = Range("Base_de_données").Rows(sbNavigator.Value)
Call LoadRecord
End Sub
 
--------------------------------------------------------------
 
Private Sub UserForm_Initialize()
With Range("Base_de_données")
    Set rgData = .Rows(2)
    Call LoadRecord
    sbNavigator.Value = 2
    sbNavigator.Max = .Rows.Count
End With
End Sub
 
--------------------------------------------------------------
 
Private Sub bnNouvelle_Click()
Dim iRowCount As Integer
 
With Range("Base_de_données")
    iRowCount = .Rows.Count + 1
    .Resize(iRowCount).Name = "Base_de_données"
    sbNavigator.Max = iRowCount
    sbNavigator.Value = iRowCount
End With
opMoteurM.Value = True
opProvenanceExterne = True
End Sub
 
--------------------------------------------------------------
 
Private Sub bnSupprimer_Click()
    If Range("Base_de_données").Rows.Count = 2 Then
        MsgBox "Impossible de supprimer la dernière Référence, elle est indispensable pour les formules", vbCritical
    Exit Sub
 
    ElseIf rgData.Row = Range("Base_de_données").Rows(2).Row Then
        Set rgData = rgData.Offset(1)
        rgData.Offsert(-1).Delete shift:=xlUp
        Call LoadRecord
    Else
        sbNavigator.Value = sbNavigator.Value - 1
        rgData.Offset(1).Delete shift:=xlUp
    End If
    sbNavigator.Max = sbNavigator.Max - 1
End Sub
 
--------------------------------------------------------------
 
Private Sub bnPrécédente_Click()
If rgData.Row > Range("Base_de_données").Rows(2).Row Then
    sbNavigator.Value = sbNavigator.Value - 1
End If
End Sub
 
--------------------------------------------------------------
 
Private Sub bnSuivante_Click()
With Range("Base_de_données")
    If rgData.Row < .Rows(.Rows.Count).Row Then
    sbNavigator.Value = sbNavigator.Value + 1
    End If
End With
End Sub
 
--------------------------------------------------------------
 
Private Sub bnOK_Click()
   Call SaveRecord
   Unload Me
End Sub
 
--------------------------------------------------------------
 
Private Sub bnAnnuler_Click()
   Unload Me
End Sub | 
Partager