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
| Private Sub Commande429_Click()
''''''''''''''''''''''''''''''''
' ENVOI devis par EMAIL VIA CDO
''''''''''''''''''''''''''''''''
' ====================================================
' Déclaration des Variables
' ====================================================
Dim A, B, C, D, e, F, W, Z, N As String
Dim G, h, I As Currency
Dim AA, AB, AC, AD, AE, af, AG, ZA, ZZ As String
Dim PJ1, PJ2, PJ3, PJ4, PJ5 As String ' Variables des PJ
A = Forms!PROPOSITIONS!FAXGES
B = Forms!PROPOSITIONS!NOMECOUR
C = Forms!PROPOSITIONS!DEVIS
D = Forms!PROPOSITIONS!REMARQ2
'N = Forms!PROPOSITIONS!NOM
Z = Forms!PROPOSITIONS!SOCI
' ====================================================
' Verif présence email
' Si sortie du msg box, on supprime le fichier créé
' ====================================================
If IsNull(A) = True Then
MsgBox ("Impossible d'envoyer le Mail car l'adresse email n'est pas renseignée dans le champ correspondant" & Chr(13) & Chr(13) & "Veuillez corriger et recommencer")
'Kill ("D:\Gescom\Temp\Devis Auto.pdf")
Exit Sub
End If
' ====================================================
imprim
DoCmd.OpenReport "Devis Auto"
' ====================================================
' Pour être certain que le fichier est créé
' ====================================================
Do While DIR("D:\Gescom\Temp\Devis Auto.pdf") = ""
DoEvents
Loop
' ====================================================
' Propose 1 à 3 PJ
' ====================================================
If MsgBox("Joindre un premier document au devis (1/3) ?", vbYesNo, ">> GERER PIECES A JOINDRE AU DEVIS :") = vbYes Then
PJ1 = OuvrirUnFichier(Application.hWndAccessApp, "Pointez un Fichier de votre choix", 1, "", "", "\\tsclient\D\Bureau")
Else:
PJ1 = ""
GoTo Suite:
End If
If MsgBox("Joindre un second document au devis (2/3) ?", vbYesNo, ">> GERER PIECES A JOINDRE AU DEVIS :") = vbYes Then
PJ2 = OuvrirUnFichier(Application.hWndAccessApp, "Pointez un Fichier de votre choix", 1, "", "", "\\tsclient\D\Bureau")
Else:
PJ2 = ""
GoTo Suite:
End If
If MsgBox("Enfin, joindre un dernier document au devis (3/3) ?", vbYesNo, ">> GERER PIECES A JOINDRE AU DEVIS :") = vbYes Then
PJ3 = OuvrirUnFichier(Application.hWndAccessApp, "Pointez un Fichier de votre choix", 1, "", "", "\\tsclient\D\Bureau")
Else:
PJ3 = ""
GoTo Suite:
End If
Suite:
If MsgBox("Voulez-vous joindre la proposition de location ?", vbYesNo, ">> PROPOSER LA SOLUTION DE LOCATION-VENTE :") = vbYes Then
DoEvents
DoEvents
DoEvents
'imprim
DoCmd.OpenReport "ET LA LOCATION"
DoEvents
DoEvents
Do While DIR("D:\Gescom\Temp\ET LA LOCATION.pdf") = ""
DoEvents
Loop
PJ4 = "D:\GESCOM\Temp\ET LA LOCATION.pdf"
Else:
PJ4 = ""
End If
' ======================================================
If MsgBox("Voulez-vous joindre le PdF de Promotion ?", vbYesNo, ">> GERER LA PROMOTION :") = vbYes Then
PJ5 = "D:\GESCOM\\Ressources\Promotion.pdf"
Else:
PJ5 = ""
End If
' ====================================================
' COnfirmer l'envoi ou Supprime le fichier créé
' ====================================================
If MsgBox("Envoyer le devis à " & Z & " ?", vbYesNo, ">> CONFIRMATION AVANT ENVOI DU DEVIS :") = vbNo Then
'Kill ("D:\Gescom\Temp\Devis Auto.pdf")
GoTo fin:
'Exit Sub
End If
' ====================================================
' Génére le fichier avec le chrono dans le nom
' ====================================================
Dim FSO
Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.CopyFile "D:\Gescom\Temp\Devis AMPF Auto.pdf", "D:\Gescom\Temp\Devis " & C & ".pdf", True
DoEvents
Set FSO = Nothing
DoEvents
DoEvents
' ====================================================
' Génère le corps du mail
' ====================================================
AA = "Bonjour " & B & " et merci pour votre demande<br/><br/>Vous trouverez notre offre de prix en pièce jointe. Les documentations techniques sont jointes, à télécharger ci-dessous ou disponibles depuis notre site web :<br/><br/>"
AB = IIf(D <> "", D, W) & "<br/>"
AC = "<br/>N'hésitez pas à me contacter pour tout complément d'information. Mon poste direct est le xx xx xx xx.<br/><br/>"
AG = "Cordiales salutations.<br/><br/>Philippe xxxxx<br/>"
ZZ = "<FONT COLOR=#000000><FONT FACE=Arial, serif><FONT SIZE=2>" & AA & AB & AC & AD & AE & af & AG & "<br><br><img src=http://image.noelshack.com/fichiers/2019/34/5/137-signature.png>
On Error GoTo Error_send
Dim oCdo As Object
Set oCdo = CreateObject("CDO.Message")
With oCdo
With .Configuration.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "serveur SMTP"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = "25" 'port utilisé
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "xxxx"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "xxx"
.Update
End With
' ====================================================
' Envoi du mail
' ===================================================
.Subject = "Devis N° " & C & " Suite à votre demande"
.From = "philippe.e@ampliconfrance.com"
.To = A
.BCC = "philippe.e@ampf.pro"
.HTMLBody = Replace(ZZ, Chr(10), "<br>")
.MDNRequested = True
.AddAttachment "D:\Gescom\Temp\Devis " & C & ".pdf"
.AddAttachment "D:\GESCOM\Ressources\CGVpdf"
If IsNull(PJ1) = False Then
.AddAttachment PJ1
End If
DoEvents
If IsNull(PJ2) = False Then
.AddAttachment PJ2
End If
DoEvents
If IsNull(PJ3) = False Then
.AddAttachment PJ3
End If
DoEvents
If IsNull(PJ4) = False Then
.AddAttachment PJ4
End If
DoEvents
If IsNull(PJ5) = False Then
.AddAttachment PJ5
End If
DoEvents
.Send
DoEvents
End With
MsgBox "Devis N° " & C & " envoyé à " & Z
' ====================================================
' Sortie de CDO + Suppression des Pdf créés
' ====================================================
fin:
Set oCdo = Nothing
If "D:\Gescom\Temp\Devis " & C & ".pdf" <> "" Then
Kill ("D:\Gescom\Temp\Devis " & C & ".pdf")
DoEvents
End If
If "D:\Gescom\Temp\Devis AMPF Auto.pdf" <> "" Then
Kill ("D:\Gescom\Temp\Devis AMPF Auto.pdf")
DoEvents
End If
If "D:\GESCOM\Temp\ET LA LOCATION.pdf" <> "" Then
Do
DoEvents
Loop Until DIR("D:\GESCOM\Temp\ET LA LOCATION.pdf") <> ""
Kill ("D:\GESCOM\Temp\ET LA LOCATION.pdf")
Do
DoEvents
Loop Until DIR("D:\GESCOM\Temp\ET LA LOCATION.pdf") = ""
DoEvents
End If
Dim ZAR1 As String
ZAR1 = "O"
Form!Envoi = ZAR1
ZAR1 = ""
'MsgBox "STEP3"
Exit Sub
' ====================================================
' Affichage erreur pour Débug
' ====================================================
Error_send:
MsgBox "Erreur d'envoi " & Err.Number & " " & Err.Description
Resume fin
End Sub |
Partager