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
| Dim WordApp As Word.Application
Dim WordDoc As Word.Document
Dim rs As DAO.Recordset
Dim ChaineSql As String
Dim x, v As Integer
Set WordApp = New Word.Application
' Ouvre document Word
Set WordDoc = WordApp.Documents.Open("" & Me.entete & "") 'chemin du modèle de facture
'Set WordDoc = WordApp.Documents.Open("C:\Users\portableM5\cloudstation 14032013\mes documents appart\facture4.docx")
' Word est visible pendant l'opération
WordApp.ShowMe
WordApp.Visible = True
'on parcourt la table facture detail pour remplir le tableau dans la facture
'1) on parcourt la table, une première fois pour récupérer les prestations détaillées provisionnées
Set rs = CurrentDb.OpenRecordset("SELECT [FACTURE].N°DOSSIER, [FACTURE].N°DOSSIER_GESTION, [FACTURE].RECAP, [FACTURE].DATEENVOI, [FACTURE].N°FACTURE, [FACTURE].N°commande, [FACTURE DETAIL].typeproduit,[FACTURE DETAIL].nature, [FACTURE DETAIL].prixunitaireHT2, [FACTURE DETAIL].quantité, [FACTURE DETAIL].totalhtligne, [FACTURE DETAIL].totalttcligne, [FACTURE DETAIL].N°commande FROM FACTURE INNER JOIN [FACTURE DETAIL] ON [FACTURE].N°commande=[FACTURE DETAIL].N°commande WHERE [FACTURE].N°dossier=" & Me.N°dossier, dbOpenDynaset)
' on compte le nombre d'enregistrements, ce sera utile pour déterminer la place dans la facture des autres prestations et des montants réclamés
w = Me.Texte159 'on le nombre de lignes prestées provisionnées dans le formulaire
x = 2 ' on ne remplit pas la première ligne du tableau
Do While Not rs.EOF
'MsgBox rs.Fields("[n°commande]") & " " & x
WordApp.ActiveDocument.Tables(1).Cell(x, 1).Range = rs.Fields("[typeproduit]")
WordApp.ActiveDocument.Tables(1).Cell(x, 4).Range = rs.Fields("[nature]")
WordApp.ActiveDocument.Tables(1).Cell(x, 2).Range = Format(rs.Fields("[prixunitaireht2]"), "#,##0.00")
WordApp.ActiveDocument.Tables(1).Cell(x, 3).Range = rs.Fields("[quantité]")
WordApp.ActiveDocument.Tables(1).Cell(x, 5).Range = Format(rs.Fields("[totalhtligne]"), "#,##0.00")
'MsgBox rs.Fields("[totalttcligne]")
rs.MoveNext
x = x + 1
Loop
Set rs = Nothing
'on parcourt la table, une seconde fois, pour récupérer les prestations facturées pour clore le dossier avec la facture récap'
Set rs = CurrentDb.OpenRecordset("select * from [FACTURE DETAIL] where n°commande=" & Me.N°commande, dbOpenDynaset)
rs.MoveFirst
x = w + 2 ' on en remplit le reste la facture en partant de la ligne qui suit la dernière ligne de la reprise de l'ensemble des prestations
v = w + 2 'c'est pour conserver la variable pour le traitement suivant
MsgBox "debut du second traitement"
MsgBox x 'correspondant à la bonne ligne de "départ" pour les aures prestations
Do While Not rs.EOF
WordApp.ActiveDocument.Tables(1).Cell(v, 1).Range = rs.Fields("[typeproduit]")
WordApp.ActiveDocument.Tables(1).Cell(v, 4).Range = rs.Fields("[nature]")
WordApp.ActiveDocument.Tables(1).Cell(v, 2).Range = Format(rs.Fields("[prixunitaireht2]"), "#,##0.00")
WordApp.ActiveDocument.Tables(1).Cell(v, 3).Range = rs.Fields("[quantité]")
WordApp.ActiveDocument.Tables(1).Cell(v, 5).Range = Format(rs.Fields("[totalhtligne]"), "#,##0.00")
rs.MoveNext
x = x + 1
Loop
Set rs = Nothing
MsgBox "fin du second traitement"
' total HT
WordApp.ActiveDocument.Tables(1).Cell(105, 3).Range = Format(Round(Me.Texte44, 2), "#,##0.00") & " "
' total TVA
WordApp.ActiveDocument.Tables(1).Cell(106, 3).Range = Format(Round(Me.TOTALTVA, 2), "#,##0.00") & " "
' TOTAL TTC (une fois le déjà versé de retiré au total ttc intermédiaire)
WordApp.ActiveDocument.Tables(1).Cell(109, 3).Range = Format(Round(Me.Texte105, 2), "#,##0.00") & " "
' TOTAL versé
WordApp.ActiveDocument.Tables(1).Cell(108, 3).Range = Format(Round(Me.Texte101, 2), "#,##0.00") & " "
' on remplit les signets comme date, référence, etc.
WordApp.ActiveDocument.Bookmarks("date").Range.text = Texte34
WordApp.ActiveDocument.Bookmarks("REFERENCE").Range.text = Texte64
WordApp.ActiveDocument.Bookmarks("NFACT").Range.text = Numfactureavocat
WordApp.ActiveDocument.Bookmarks("npl").Range.text = NPL
WordApp.ActiveDocument.Bookmarks("ADRESSE1").Range.text = Adresse1
WordApp.ActiveDocument.Bookmarks("ADRESSE2").Range.text = Adresse2
WordApp.ActiveDocument.Bookmarks("ADRESSE3").Range.text = ADRESSE3
WordApp.ActiveDocument.Bookmarks("CP").Range.text = CP
WordApp.ActiveDocument.Bookmarks("ville").Range.text = ville
WordApp.ActiveDocument.Bookmarks("totalttc").Range.text = Nb2Mot$(Me.Texte105) & " TTC"
'Application.ScreenUpdating = False
Dim Tbl As Table, cel As Cell, i As Long, n As Long, fEmpty As Boolean
'code pour les colonnes vides
'With ActiveDocument
' For Each Tbl In .Tables
' n = Tbl.Columns.Count
' For i = n To 1 Step -1
' fEmpty = True
' For Each cel In Tbl.Columns(i).Cells
' If Len(cel.Range.text) > 2 Then
' fEmpty = False
' Exit For
' End If
' Next cel
' If fEmpty = True Then Tbl.Columns(i).Delete
' Next i
'Next Tbl
'End With
With WordApp.ActiveDocument
For Each Tbl In .Tables
n = Tbl.Rows.Count
For i = n To 1 Step -1
fEmpty = True
For Each cel In Tbl.Rows(i).Cells
If Len(cel.Range.text) > 2 Then
fEmpty = False
Exit For
End If
Next cel
If fEmpty = True Then Tbl.Rows(i).Delete
Next i
Next Tbl
End With
Set cel = Nothing: Set Tbl = Nothing
'Application.ScreenUpdating = True
WordApp.ActiveDocument.SaveAs Forms!consultation_dossier!Texte101 & "\" & Texte26 & "\" & Texte66 & " factures\Facture Recapitulative N" & Me.Numfactureavocat & "_N°dossier_" & Me.Texte26 & ".DOC"
DoCmd.Close
err:
MsgBox err.Number & " " & err.Description |
Partager