Good morning everyone, I use this VBA below to email documents to the customers. Almost everything works as I would like, but I still have a "problem", hence my question: I have to open the reports first before Access wants to add them as an attachment, otherwise I get the message that it cannot find them. Can anyone also help me get the system to add the reports without actually having to open them? If possible, also with a little explanation so that I can learn from it......
Thanks in advance for your cooperation
Sincerely,
Richard
Dim OutlookApp As Object
Dim OutlookMail As Object
Dim Report As Report
Dim Report2 As Report
Dim TempFolder As String
Dim TempPDF1 As String
Dim TempPDF2 As String
' Maak een nieuw Outlook-e-mailbericht
Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookMail = OutlookApp.CreateItem(0)
' Bepaal de tijdelijke map om de PDF-bestanden op te slaan
TempFolder = Environ("TEMP") & ""
' Voeg rapporten toe als bijlagen (in PDF-formaat)
Set Report = Reports("Rapport")
TempPDF1 = TempFolder & "Rapport.pdf"
TempPDF2 = TempFolder & "Maandlijst.pdf"
' Exporteer rapporten naar PDF-bestanden
DoCmd.OutputTo acOutputReport, "Rapport", acFormatPDF, TempPDF1
DoCmd.OutputTo acOutputReport, "Maandlijst", acFormatPDF, TempPDF2
' Voeg PDF-bestanden toe als bijlagen
OutlookMail.Attachments.Add TempPDF1
OutlookMail.Attachments.Add TempPDF2
' Instellingen voor het e-mailbericht
With OutlookMail
.To = Forms!ContactFrm!Email ' Vervang door het e-mailadres van de ontvanger
.BCC = "mailadres"
.Subject = "Keuring rapport(en) als bijlage"
.Body = "Beste klant," & vbCrLf & _
"In de bijlage vindt u het keuringsrapport van uw AED en een nieuwe maand-controle lijst." & vbCrLf & vbCrLf & _
"Met vriendelijke groet, Richard"
.Display ' Als je het e-mailbericht handmatig wilt verzenden, gebruik dan .Display (.Send)