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
| Private Sub Ouvrir_facture_Click()
DoCmd.OpenReport "Factures", acViewPreview, , "ID_Facture=" & ID_Facture
Dim fichier As String
Dim base As Database: Dim requete As String
' Late Binding
'1) déclaration des objets
Dim client_msg As Object
Dim message As Object
'Dim client_msg As New Outlook.Application
'Dim message As Outlook.MailItem
'2) affectation des objets
Set client_msg = CreateObject("Outlook.Application")
Set message = client_msg.CreateItem(olMailItem)
Dim Adresse As String
Adresse = Nz(DFirst("Mail", "T_Clients", "ID_Client=" & ID_Client.Value), "")
fichier = Application.CurrentProject.Path & "\archives_factures\locations\Facture " & Parent!NomPrenom.Value & " (" & ID_Facture.Value & ")" & ".pdf"
DoCmd.OutputTo acOutputReport, , acFormatPDF, fichier, False
Set base = Application.CurrentDb
requete = "UPDATE T_Factures SET Facture_Loc='Facture " & Parent!NomPrenom.Value & " (" & ID_Facture.Value & ")" & ".pdf' WHERE ID_Facture=" & ID_Facture.Value
base.Execute requete
Set ligne = base.OpenRecordset("SELECT Mail FROM T_Clients WHERE ID_Client=" & ID_Client.Value, dbOpenDynaset)
Adresse = Nz(ligne![Mail], "")
ligne.Close
base.Close
Set ligne = Nothing
Set base = Nothing
If Adresse Like "*@*.*" Then
If (MsgBox("Joindre la facture par mail ?", vbYesNo) = 6) Then
Set message = client_msg.CreateItem(olMailItem)
With message
.Recipients.Add Adresse
.Subject = "Votre facture"
.Body = "Cher(e) client(e)," & Chr(13) & Chr(10) & Chr(13) & Chr(10) & "Veuillez trouver ci-joint votre facture de location." & Chr(13) & Chr(10) & Chr(13) & Chr(10) & "Cordialement." & Chr(13) & Chr(10) & "L'équipe RL."
.Attachments.Add fichier
.Send
End With
End If
End If
Set client_msg = Nothing
Set message = Nothing
End Sub |
Partager