Results 1 to 4 of 4
  1. #1
    Bunic000 is offline Novice
    Windows 10 Office 365
    Join Date
    Oct 2023
    Posts
    8

    Open report

    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)

  2. #2
    Minty is online now VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    The simple explanation is that until Access opens the report to create the PDF, there is nothing to attach.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    I think all you need to do is to comment out\remove this line (not used anywhere):
    Code:
    Set Report = Reports("Rapport")
    The Reports() collection holds the open reports therefore the error, but you do not need\use that in your code.
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  4. #4
    Bunic000 is offline Novice
    Windows 10 Office 365
    Join Date
    Oct 2023
    Posts
    8
    Thanks, it worked with the code: DoCmd.OpenReport "Report", acViewReport, , "ControleID = " & Me.ControleID, acHidden
    and the code DoCmd.OpenReport "Monthly List", acViewReport, , "ControleID = " & Me.ControleID, acHidden


    Access now uses two PDF reports without opening them.


    Have a nice day

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 02-28-2017, 02:45 PM
  2. Replies: 2
    Last Post: 03-13-2016, 02:01 PM
  3. Replies: 4
    Last Post: 12-09-2015, 09:02 AM
  4. Replies: 3
    Last Post: 07-22-2014, 11:37 AM
  5. Help on report to open form to open query...
    By saseymour in forum Programming
    Replies: 13
    Last Post: 07-16-2013, 08:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums