1 2 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
|
Private Sub CmdLSuiv_Click()
Dim obj1 As String, obj2 As String, term As String, BaseD As String
If Val(Range("V8")) = 1 Then
obj1 = "la facture :"
obj2 = "facture"
term = "e"
BaseD = "BD_FACTURES"
ElseIf Val(Range("V8")) = 2 Then
obj1 = "le devis :"
obj2 = "devis"
term = ""
BaseD = "BD_DEVIS"
Else
Exit Sub
End If
Dim i, N, j
For i = 1 To 3
N = N + Controls("OptType" & i).Value
Next i
'Traiter la ligne en cours
If Val(Me.ZtxtPrxUnit.Value) <> Empty And Val(Me.ZtxtQte.Value) = Empty Then 'Ne pas enregistrer ligne nulle
Beep
MsgBox "Vous ne pouvez pas valider une référence sans préciser sa quantité !", vbExclamation, "Action impossible !"
Exit Sub
ElseIf Val(Me.ZtxtPrxUnit.Value) <> Empty And Val(Me.ZtxtQte.Value) = 0 Then
Me.ZtxtMontant = 0
ElseIf Val(Me.ZtxtCode.Value) = 0 And Val(Me.ZtxtMontant.Value) <> 0 Then
MsgBox "Vous ne pouvez pas enregistrer une référence sans préciser son code !", vbExclamation, "Action impossible !"
Exit Sub
ElseIf Val(Me.CboxDesignation.ListIndex) = -1 Then
MsgBox "Vous devez sélectionner une référence pour pouvoir éditer une nouvelle ligne !", vbExclamation, "Action impossible !"
Exit Sub
'On teste les saisies...
ElseIf Me.CboxIdClient.Text = Empty Then
MsgBox "Vous devez impérativement entrer ou sélectionner un ID CLIENT !", vbExclamation, "Erreur de sélection !"
CboxIdClient.SetFocus
Exit Sub
'On teste les options
ElseIf N = 0 Then
MsgBox "Vous devez impérativement sélectionner un type de " & obj2 & " !", vbExclamation, "Sélection obligatoire !"
Exit Sub
ElseIf Me.CboxDesignation.Text = Empty And Me.ZtxtNligne < 2 Then
MsgBox "Vous devez impérativement sélectionner une référence pour éditer " & obj1 & " !", vbExclamation, "Sélection Manquante !"
CboxDesignation.SetFocus
Exit Sub
ElseIf Val(Me.ZtxtRemise.Value) < 0 And Val(Me.ZtxtRemise.Value) > 100 Then
MsgBox "Vous devez saisir une valeur comprise entre 0 et 100", vbInformation, "Information"
Exit Sub
Else 'enregistrer la ligne
Cells(Range("V13").Value, 2) = Me.ZtxtNligne.Value
Cells(Range("V13").Value, 6) = Me.CboxDesignation.Value
Cells(Range("V13").Value, 14) = Me.ZtxtPrxUnit.Value
Cells(Range("V13").Value, 16) = Me.ZtxtQte.Value
Cells(Range("V13").Value, 19) = Me.ZtxtCode.Value
Cells(Range("V13").Value, 23) = Me.ZtxtPref.Value
Cells(Range("V13").Value, 24) = Me.ZtxtRef.Value
End If
'Passer à la ligne suivante
If Me.CboxDesignation.ListIndex <> -1 Then
Range("V13").Value = Range("V13").Value + 1
Else
Exit Sub
End If
'Info nombre de ligne max atteint
If Val(ZtxtNligne.Value) = 28 Then
MsgBox "Vous avez édité le nombre maximum de lignes," & Chr(10) & "pouvant être contenues dans la facture.", vbInformation, "Maximum atteint"
End If
'Initialiser les champs
If Cells(Range("V13").Value, 1) <> "" Then
'Édition de ligne existante
Me.ZtxtNligne.Value = Cells(Range("V13").Value, 2)
Me.CboxDesignation.Value = Cells(Range("V13").Value, 6)
Me.ZtxtPrxUnit.Value = Cells(Range("V13").Value, 14)
Me.ZtxtQte.Value = Cells(Range("V13").Value, 16)
Me.ZtxtCode.Value = Cells(Range("V13").Value, 19)
Me.ZtxtPref.Value = Cells(Range("V13").Value, 23)
Me.ZtxtRef.Value = Cells(Range("V13").Value, 24)
Call InitialiseTotaux
Else
Call NouvelleLigne
End If
Me.CboxDesignation.SetFocus 'Activer le 1er champ
'On affecte leur valeur
Dim IdFact As String
For Each j In FrmDevisFacture.TypeFacture.Controls
If j = True Then IdFact = j.Caption
Next j
If Me.ZtxtNligne.Value >= 1 And Me.ZtxtNligne.Value <= 28 And Me.ZtxtNligne.Enabled = True Then
'On envoi les données sur la Facture
With Sheets("Devis_Facture")
.Range("W6").Value = Me.ZtxtNumFact.Value
.Range("U2").Value = Me.ZtxtFormeJuridique.Value
.Range("V2").Value = Me.ZtxtRaisonSociale.Value
.Range("W2").Value = Me.ZtxtCivilite.Value
.Range("U8").Value = Me.ZtxtFonction.Value
.Range("Y2").Value = Me.ZtxtNom.Value
.Range("X2").Value = Me.ZtxtPrenom.Value
.Range("Z2").Value = Me.ZtxtAdresseL1.Value
.Range("AA2").Value = Me.ZtxtAdresseL2.Value
.Range("U4").Value = Me.ZtxtCodePostal.Value
.Range("V4").Value = Me.ZtxtVille.Value
.Range("U6").Value = Me.CboxIdClient.Value
.Range("Z6").Value = Me.ZtxtDate.Value
.Range("V6").Value = IdFact
.Range("P50").Value = Me.ZtxtAcompte.Value
If Me.ZtxtRemise.Value <> Empty Then
.Range("T48").Value = Me.ZtxtRemise.Value / 100
Else
.Range("T48").Value = Me.ZtxtRemise.Value
End If
End With
End If
Call InitialiseTotaux
End Sub |
Partager