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
| Private Sub Commande192_Click()
''''''''''''''''''''''''''''''''
' ENVOI AR par EMAIL VIA CDO
''''''''''''''''''''''''''''''''
' ====================================================
' Impirmer la pièces avant de la traiter par email :
' ====================================================
Me.DATECH.SetFocus
imprim
DoCmd.OpenReport "AR Auto"
' ====================================================
' Pour être certain que le fichier est crée
' ====================================================
Do While DIR("D:\Gescom\Temp\AR Auto.pdf") = ""
DoEvents
Loop
' ====================================================
' Déclaration des Variables
' ====================================================
Dim A As String, B As String, C As String, D As String, e As String, F As String, X As String, AL As String, CL As String, VL As String
Dim REMA As Variant
Dim G As Currency, h As Currency, I As Currency
Dim AA As String, AB As String, AC As String, AD As String, AE As String, af As String, AG As String, ZA As String, ZZ As String
A = Forms!CDCLI!FAX
B = Forms!CDCLI!NUMCLI
C = Forms!CDCLI!ARNO
D = Forms!CDCLI!DATECDE
e = Forms!CDCLI!CDREG
F = Forms!CDCLI!DELAICLI
G = Format(Forms!CDCLI!TOTALTTC, "0.00")
X = Forms!CDCLI!SOCIETE
AL = Forms!CDCLI![SOCIETE-LIV]
CL = Forms!CDCLI![CD-LIV]
VL = Forms!CDCLI![VILLE-LIV]
If Forms!CDCLI![REMARQ] = "" Then
REMA = ""
Else
REMA = "Remarques complémentaires figurant sur l'AR joint : <br/>" & Forms!CDCLI![REMARQ]
End If
MsgBox (F)
' ====================================================
' Verif présence email puis délais
' Si sortie du msg box, on supprime le fichier créé
' ====================================================
If A = "" Then
MsgBox (Chr(13) & "Impossible d'envoyer le Mail : Il n'y a pas d'adresse email dans la case correspondante" & Chr(13) & Chr(13) & "Veuillez corriger et recommencer")
Kill ("D:\Gescom\Temp\AR Auto.pdf")
Exit Sub
End If
If Len(F) = 0 Then
MsgBox ("Impossible d'envoyer le Mail : Le Délai n'est pas renseigné" & Chr(13) & Chr(13) & "Veuillez corriger et recommencer")
Kill ("D:\Gescom\Temp\AR Auto.pdf")
Exit Sub
End If
' ====================================================
' COnfirmer l'envoi ou Supprime le fichier créé
' ====================================================
If MsgBox("Confirmez l'envoi de l'AR de Commande au client " & X & " ?", vbYesNo, "Demande de confirmation") = vbNo Then
Kill ("D:\Gescom\Temp\AR Auto.pdf")
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\AR Auto.pdf", "D:\Gescom\Temp\AR " & C & ".pdf", True
Set FSO = Nothing
' ====================================================
' Génère le corps du mail
' ====================================================
DoEvents
AA = "Ceci est un message Automatique." & "<br/><br/>" & "Madame, Monsieur,<br/><br/>Nous vous remercions vivement pour votre ordre dont nous en accusons réception. Les principales informations sont rappelées ci-dessous :<br/><br/>"
AB = "N/REF : " & C & "<br/><br/>"
AC = "Votre commande N° " & B & " du " & D & "<br/>Montant TTC : " & G & " EUR<br/>Règlement : " & e
AD = "<br/>==========================<br/>Date de Livraison initiale : " & F & "<br/>==========================<br/><br/> Lieu de Livraison : " & AL & " - " & CL & " " & VL & "<br>"
DoEvents
AE = "<br/><U/>Le délai ci-dessus est théorique (délai maximum constaté). En cas de modification, vous receverez alors un nouvel AR.<br/></U><br/>Votre interlocuteur commercial est à votre disposition pour vous apporter toute précision complémentaire.<br/>"
AG = "<br/>Cordiales Salutations<br/>"
DoEvents
DoEvents
On Error GoTo Error_send
Dim oCdo As Object
Set oCdo = CreateObject("CDO.Message")
With oCdo
With .Configuration.Fields
DoEvents
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.free.fr" 'nom ou IP du 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") = "administratif@toto.fr"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "xxxxxx"
DoEvents
.Update
DoEvents
End With
' ====================================================
' Envoi du mail
' ====================================================
.Subject = "AR de votre Commande N° " & B
.From = "administratif@toto.fr"
.To = A
.HTMLBody = ZZ & "<br><br><img src=https://i.goopics.net/xx.png>" ' corps du message en format texte brut
.MDNRequested = True
.AddAttachment "D:\Gescom\Temp\AR " & C & ".pdf"
DoEvents
.Send
End With
' ====================================================
' Index OK pour indiqué que le mail est envoyé
' ====================================================
MsgBox "AR de Commande envoyé à " & X & " !"
Dim ZAR1 As String
ZAR1 = "O"
Form!AR1 = ZAR1
' ====================================================
' Sortie de CDO + Suppression des Pdf créés
' ====================================================
fin:
Set oCdo = Nothing
If "D:\Gescom\Temp\AR Auto.pdf" <> "" Then
Kill ("D:\Gescom\Temp\AR Auto.pdf")
End If
If "DD:\Gescom\Temp\AR " & C & ".pdf" <> "" Then
Kill ("D:\Gescom\Temp\AR " & C & ".pdf")
End If
Exit Sub
' ====================================================
' Affichage erreur pour Débug
' ====================================================
Error_send:
MsgBox "Erreur d'envoi " & Err.Number & " " & Err.Description
Resume fin
End Sub |
Partager