PDF save selection

paul.brisenden

New member
Local time
Today, 12:59
Joined
Feb 6, 2025
Messages
24
Can anyone help. I have managed to build a database with subforms which i plan to use instead of a word document we currently fill out and send. i know very little about filters and queries. is anyone willing to help me set up a save to pdf for a selected record on 4 subforms. Im at a loss here.
 
Probably best to create a report, and just output that to a pdf file.
Easy enough to open a report to a filtered set of records or just the one.
 
Probably best to create a report, and just output that to a pdf file.
Easy enough to open a report to a filtered set of records or just the one.
Thanks for the reply Gasman, my issue is that i have outstretched my knowledge now. would i theoretically be able to place a macro button that once pressed, would simply save that individual record as a PDF. i have attempted to do so but it saves every record within that tabbed form.
 
That is because you are not using any filter.
For a report (from chatgpt), very simple, hardcoded, but shows the logic.
Code:
Sub ExportReportForRecord()
    Dim recordID As Long
    Dim reportName As String
    Dim filter As String
    Dim outputPath As String

    ' === Set these values ===
    recordID = 123              ' <-- Change this to your selected record ID
    reportName = "MyReport"     ' <-- Name of your report
    outputPath = "C:\Reports\MyReport_" & recordID & ".pdf" ' Output file path

    ' === Filter to select the record ===
    filter = "[ID] = " & recordID   ' <-- Change [ID] to your primary key field

    ' === Open report in hidden mode, filtered to record ===
    DoCmd.OpenReport reportName, acViewPreview, , filter

    ' === Output to PDF ===
    DoCmd.OutputTo acOutputReport, reportName, acFormatPDF, outputPath, False

    ' === Close the report ===
    DoCmd.Close acReport, reportName

    MsgBox "Report exported to: " & outputPath
End Sub
 
That is because you are not using any filter.
For a report (from chatgpt), very simple, hardcoded, but shows the logic.
Code:
Sub ExportReportForRecord()
    Dim recordID As Long
    Dim reportName As String
    Dim filter As String
    Dim outputPath As String

    ' === Set these values ===
    recordID = 123              ' <-- Change this to your selected record ID
    reportName = "MyReport"     ' <-- Name of your report
    outputPath = "C:\Reports\MyReport_" & recordID & ".pdf" ' Output file path

    ' === Filter to select the record ===
    filter = "[ID] = " & recordID   ' <-- Change [ID] to your primary key field

    ' === Open report in hidden mode, filtered to record ===
    DoCmd.OpenReport reportName, acViewPreview, , filter

    ' === Output to PDF ===
    DoCmd.OutputTo acOutputReport, reportName, acFormatPDF, outputPath, False

    ' === Close the report ===
    DoCmd.Close acReport, reportName

    MsgBox "Report exported to: " & outputPath
End Sub
sorry gasman, thats a bit beyond me. i have managed to fluke my way through this so far but im now stuck with very little understanding of building code. most of this has been done with macros so far.
 
When you say macro, are you actually meaning Access macro?, as with Excel, VBA code is called a macro.
There is no substitute for learning.
That snippet of code explains each step.

If you just want to print the form, you can do it manually and select pdf output.

Ctrl+P on the form will allow this
1744804142762.png


Unfortunately Access does not have a record macro option, (which just records the steps in VBA).

Edit: Youtube has videos that should help? Not just for this topic either.
 
Last edited:
How have you created the form and sub forms? I think you may have used the form wizard..

You could build a query in a similar way if I'm going down the right path. Then the report wizard would do the same.

The macro section would then be able to output the report as pdf.

A few steps without any coding.

It would be helpful if you could let us know what version of access your using.
 

Users who are viewing this thread

Back
Top Bottom