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 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 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
|
Option Compare Database
Option Explicit
Public xl As Excel.Application
Public wbk As Excel.Workbook, wst As Excel.Worksheet
Dim db As DAO.Database, rst As DAO.Recordset
Public sstot1 As Integer, sstot2 As Integer, sstot As Integer
Public Nblignes As Integer
Public Libellé1A As String, Libellé1B As String, Libellé1C As String
Public Quantité1 As Integer, Prixunitaire1 As Integer, Montant1 As Integer
Public Libellé2A As String, Libellé2B As String, Libellé2C As String
Public Quantité2 As Integer, Prixunitaire2 As Integer, Montant2 As Integer
Public Libellé3A As String, Libellé3B As String, Libellé3C As String
Public Quantité3 As Integer, Prixunitaire3 As Integer, Montant3 As Integer
Public Libellé4A As String, Libellé4B As String, Libellé4C As String
Public Quantité4 As Integer, Prixunitaire4 As Integer, Montant4 As Integer
Public Libellé5A As String, Libellé5B As String, Libellé5C As String
Public Quantité5 As Integer, Prixunitaire5 As Integer, Montant5 As Integer
Public Libellé6A As String, Libellé6B As String, Libellé6C As String
Public Quantité6 As Integer, Prixunitaire6 As Integer, Montant6 As Integer
Public Libellé7A As String, Libellé7B As String, Libellé7C As String
Public Quantité7 As Integer, Prixunitaire7 As Integer, Montant7 As Integer
Public Libellé8A As String, Libellé8B As String, Libellé8C As String
Public Quantité8 As Integer, Prixunitaire8 As Integer, Montant8 As Integer
Public Libellé9A As String, Libellé9B As String, Libellé9C As String
Public Quantité9 As Integer, Prixunitaire9 As Integer, Montant9 As Integer
Public Libellé10A As String, Libellé10B As String, Libellé10C As String
Public Quantité10 As Integer, Prixunitaire10 As Integer, Montant10 As Integer
Public Nom As String, Adresse As String, Codepostal As String, Ville As String
Public Réponse As Integer, strSQL As String
Sub ImpressionFacture()
Set db = CurrentDb
'Saisie du numéro de facture pour impression
Réponse = Val(InputBox("Saisissez le N° de facture Bok :", "Saisie N° Facture"))
strSQL = "SELECT Factures.*, Clients.[Nom], Clients.[Adresse], Clients.[Codepostal], Clients.[Ville] FROM Clients RIGHT JOIN Factures ON Clients.[Id client] = Factures.[IdClient] WHERE [Factures].[FactureMB]=" & Réponse & ";"
Set rst = db.OpenRecordset(strSQL, dbOpenDynaset)
Set xl = New Excel.Application ' Démarre Excel et ouvre la feuille Facture.xlsx
xl.Visible = True
Set wbk = xl.Workbooks.Open("C:\Documents and settings\Boks\FactureOK.xlsx")
If rst("Nblignes") <= 6 Then ' Traitement pour lignes de facture 1 à 6
Set wst = wbk.Worksheets(1) ' Feuille Excel 1
With wst
Début
'***********************************************************************
If rst("Nblignes") = 1 Then
Procédure1
sstot1 = Nz(rst("Montant1"))
End If
'***********************************************************************
If rst("Nblignes") = 2 Then
Procédure1
Procédure2
sstot1 = Nz(rst("Montant1")) + Nz(rst("Montant2"))
End If
'************************************************************
If rst("Nblignes") = 3 Then
Procédure1
Procédure2
Procédure3
sstot1 = Nz(rst("Montant1")) + Nz(rst("Montant2")) + Nz(rst("Montant3"))
End If
'************************************************************
If rst("Nblignes") = 4 Then
Procédure1
Procédure2
Procédure3
Procédure4
sstot1 = Nz(rst("Montant1")) + Nz(rst("Montant2")) + Nz(rst("Montant3")) + Nz(rst("Montant4"))
End If
'***********************************************
If rst("Nblignes") = 5 Then
Procédure1
Procédure2
Procédure3
Procédure4
Procédure5
sstot1 = Nz(rst("Montant1")) + Nz(rst("Montant2")) + Nz(rst("Montant3")) + Nz(rst("Montant4")) + Nz(rst("Montant5"))
End If
'***********************************************************************
If rst("Nblignes") = 6 Then
Procédure1
Procédure2
Procédure3
Procédure4
Procédure5
Procédure6
sstot1 = Nz(rst("Montant1")) + Nz(rst("Montant2")) + Nz(rst("Montant3")) + Nz(rst("Montant4")) + Nz(rst("Montant5")) + Nz(rst("Montant6"))
End If
'***************************************************************************
wst.Range("D46").Value = "En votre aimable règlement"
wst.Range("C48").Value = sstot1
wst.Range("H48").Value = sstot1
End With
'*************************************************************************************
Else '(plus de 6 lignes de facture)
'*************************************************************************************
Set wst = wbk.Worksheets(1) ' Feuille Excel 1
With wst
Début
Procédure1
Procédure2
Procédure3
Procédure4
Procédure5
Procédure6
wst.Range("D46").Value = "En votre aimable règlement"
wst.Range("C48").Value = sstot1
wst.Range("H48").Value = sstot1
End With
' Feuille Excel 2
Set wst = wbk.Worksheets(2)
With wst
Début
Select Case rst("Nblignes")
Case 7
Procédure7
Case 8
Procédure7
Procédure8
Case 9
Procédure7
Procédure8
Procédure9
Case 10
Procédure7
Procédure8
Procédure9
Procédure10
End Select
wst.Range("D46").Value = "En votre aimable règlement"
If rst("Nblignes") = 7 Then
sstot2 = Nz(rst("Montant7"))
End If
If rst("Nblignes") = 8 Then
sstot2 = Nz(rst("Montant7")) + Nz(rst("Montant8"))
End If
If rst("Nblignes") = 9 Then
sstot2 = Nz(rst("Montant7")) + Nz(rst("Montant8")) + Nz(rst("Montant9"))
End If
If rst("Nblignes") = 10 Then
sstot2 = Nz(rst("Montant7")) + Nz(rst("Montant8")) + Nz(rst("Montant9")) + Nz(rst("Montant10"))
End If
sstot = sstot1 + sstot2
wst.Range("C48").Value = sstot2
wst.Range("H48").Value = sstot
End With
FIN:
End If
End Sub
Sub Procédure1()
wst.Range("B23").Value = rst("Quantité1")
wst.Range("D23").Value = rst("Libellé1A")
wst.Range("D24").Value = rst("Libellé1B")
wst.Range("D25").Value = rst("Libellé1C")
wst.Range("G23").Value = rst("Prixunitaire1")
wst.Range("H23").Value = rst("Montant1")
End Sub
Sub Procédure2()
wst.Range("B27").Value = rst("Quantité2")
wst.Range("D27").Value = rst("Libellé2A")
wst.Range("D28").Value = rst("Libellé2B")
wst.Range("D29").Value = rst("Libellé2C")
wst.Range("G27").Value = rst("Prixunitaire2")
wst.Range("H27").Value = rst("Montant2")
End Sub
Sub Procédure3()
wst.Range("B31").Value = rst("Quantité3")
wst.Range("D31").Value = rst("Libellé3A")
wst.Range("D32").Value = rst("Libellé3B")
wst.Range("D33").Value = rst("Libellé3C")
wst.Range("G31").Value = rst("Prixunitaire3")
wst.Range("H31").Value = rst("Montant3")
End Sub
Sub Procédure4()
wst.Range("B35").Value = rst("Quantité4")
wst.Range("D35").Value = rst("Libellé4A")
wst.Range("D36").Value = rst("Libellé4B")
wst.Range("D37").Value = rst("Libellé4C")
wst.Range("G35").Value = rst("Prixunitaire4")
wst.Range("H35").Value = rst("Montant4")
End Sub
Sub Procédure5()
wst.Range("B39").Value = rst("Quantité5")
wst.Range("D39").Value = rst("Libellé5A")
wst.Range("D40").Value = rst("Libellé5B")
wst.Range("D41").Value = rst("Libellé5C")
wst.Range("G39").Value = rst("Prixunitaire5")
wst.Range("H39").Value = rst("Montant5")
End Sub
Sub Procédure6()
wst.Range("B43").Value = rst("Quantité6")
wst.Range("D43").Value = rst("Libellé6A")
wst.Range("D44").Value = rst("Libellé6B")
wst.Range("D45").Value = rst("Libellé6C")
wst.Range("G43").Value = rst("Prixunitaire6")
wst.Range("H43").Value = rst("Montant6")
End Sub
Sub Procédure7()
wst.Range("B23").Value = rst("Quantité7")
wst.Range("D23").Value = rst("Libellé7A")
wst.Range("D24").Value = rst("Libellé7B")
wst.Range("D25").Value = rst("Libellé7C")
wst.Range("G23").Value = rst("Prixunitaire7")
wst.Range("H23").Value = rst("Montant7")
End Sub
Sub Procédure8()
wst.Range("B27").Value = rst("Quantité8")
wst.Range("D27").Value = rst("Libellé8A")
wst.Range("D28").Value = rst("Libellé8B")
wst.Range("D29").Value = rst("Libellé8C")
wst.Range("G27").Value = rst("Prixunitaire8")
wst.Range("H27").Value = rst("Montant8")
End Sub
Sub Procédure9()
wst.Range("B31").Value = rst("Quantité9")
wst.Range("D31").Value = rst("Libellé9A")
wst.Range("D32").Value = rst("Libellé9B")
wst.Range("D33").Value = rst("Libellé9C")
wst.Range("G31").Value = rst("Prixunitaire9")
wst.Range("H31").Value = rst("Montant9")
End Sub
Sub Procédure10()
wst.Range("B35").Value = rst("Quantité10")
wst.Range("D35").Value = rst("Libellé10A")
wst.Range("D36").Value = rst("Libellé10B")
wst.Range("D37").Value = rst("Libellé10C")
wst.Range("G35").Value = rst("Prixunitaire10")
wst.Range("H35").Value = rst("Montant10")
End Sub
Sub Début()
wst.Range("F9").Value = rst("Nom")
wst.Range("F10").Value = rst("Adresse")
wst.Range("F11").Value = rst("Codepostal")
wst.Range("G11").Value = rst("Ville")
wst.Range("C16").Value = rst("FactureMB")
wst.Range("G16").Value = Date
wst.Range("A19").Value = rst("Notre référence")
wst.Range("B19").Value = rst("Mode d'envoi")
wst.Range("D19").Value = rst("Votre référence")
wst.Range("E19").Value = rst("Date de commande")
wst.Range("G19").Value = rst("Date de livraison1")
wst.Range("H19").Value = rst("IdClient")
End Sub |
Partager