Help on access

Mark Powell 0 Reputation points
2025-11-07T13:04:48.4166667+00:00

i have a cmd button that currently once pressed opened outlook, populates with names and attached a report.

is there a way a pdf can be used in the replace of the report?

Microsoft 365 and Office | Access | For home | Windows
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Dora-T 8,520 Reputation points Microsoft External Staff Moderator
    2025-11-07T14:42:45.9433333+00:00

    Hi @Mark Powell

    Thank you for reaching out to the Microsoft Q&A Forum. 

    Based on your description, I tried creating a basic setup and tested it on my side, and it worked for me. You can refer to the steps below: 

    1.Create a simple table, build a query to summarize the data, and then create a report based on that query. 

    2.Add a command button to a form. 

    User's image

    3.Run the following VBA code to export the report as a PDF and send it via Outlook: 

    Private Sub Command0_Click() 
        On Error GoTo ErrHandler 
         Dim rptName As String 
        Dim pdfPath As String 
        Dim olApp As Object 
        Dim olMail As Object 
         rptName = "rptSalesSummary" 
        pdfPath = Environ$("TEMP") & "\" & rptName & "_" & Format(Now, "yyyymmdd_hhnnss") & ".pdf" 
         DoCmd.OutputTo acOutputReport, rptName, acFormatPDF, pdfPath, False 
         Set olApp = CreateObject("Outlook.Application") 
        Set olMail = olApp.CreateItem(0) 
         With olMail 
            .To = "enter_recipient_email_here" 
            .Subject = "Sales Report (PDF)" 
            .Body = "Hello," & vbCrLf & vbCrLf & _ 
                    "Please find the attached PDF report." & vbCrLf & vbCrLf & _ 
                    "Best regards." 
            .Attachments.Add pdfPath 
            .Send 
        End With 
     Cleanup: 
        Set olMail = Nothing 
        Set olApp = Nothing 
        Exit Sub 
     ErrHandler: 
        MsgBox "Error " & Err.Number & ": " & Err.Description, vbExclamation 
        Resume Cleanup 
    End Sub
    
    

    Could you let me know if this is what you were hoping to achieve? If so, please adjust the code and steps to fit your setup.  

    User's image

    User's image

    I hope this helps. 


    If the answer is partially helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread. 

    0 comments No comments

  2. Mark Powell 0 Reputation points
    2025-11-07T15:16:13.9066667+00:00

    hi. im not looking to export a report to pdf, but have a actual standard pdf sent to a client by pressing the command button. thanks for any help


  3. Karl Donaubauer 2,696 Reputation points MVP
    2025-11-07T18:10:24.85+00:00

    Hi,

    Show us the current code behind the button. Then we might be able to show you what you need to change.

    Servus
    Karl


    Access Forever News DevCon
    Access-Entwickler-Konferenz AEK

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.