A fillable PDF is a document that allows users to enter data into fields without modifying the rest of the content. Fillable PDFs are useful for forms, surveys, applications, and other purposes that require user input.
One way to create a fillable PDF is to use Adobe Acrobat, a software that can edit and convert PDF files. However, if you have an Access database and want to generate a fillable PDF from an Access form, you can use a different method that involves VBA code and a third-party library.
The basic steps to create a fillable PDF from an Access form are:
- Download and install the CutePDF Form SDK, a library that allows you to manipulate PDF files programmatically. You will need a license key to use this library.
- Create a fillable PDF template using Adobe Acrobat or another tool. This template should have the same layout and fields as your Access form, but without any data. Save the template as a PDF file in a folder that your Access database can access.
- Write a VBA function that uses the CutePDF Form SDK to open the PDF template, fill in the fields with data from your Access form, and save the result as a new PDF file. You can use the examples and documentation provided by the CutePDF website to help you write the code.
- Add a button or a macro to your Access form that calls the VBA function and passes the relevant parameters, such as the file name and path of the PDF template and the output PDF file.
Here is an example of a VBA function that creates a fillable PDF from an Access form:
'Create a fillable PDF from an Access form
Public Function CreatePDF(ByVal TemplateFile As String, ByVal OutputFile As String) As Boolean
'Declare variables
Dim Filler As Object 'CutePDF Form Filler object
Dim FieldName As String 'Name of the field in the PDF template
Dim FieldValue As String 'Value of the field from the Access form
Dim FieldCount As Long 'Number of fields in the PDF template
Dim i As Long 'Loop counter
'Create a new instance of the CutePDF Form Filler object
Set Filler = CreateObject("CPFiller.CPFillerCtrl.1")
'Open the PDF template file
If Filler.OpenFile(TemplateFile, "") <> 0 Then
MsgBox "Failed to open the PDF template file.", vbCritical
Exit Function
End If
'Get the number of fields in the PDF template
FieldCount = Filler.GetFieldCount()
'Loop through each field in the PDF template
For i = 1 To FieldCount
'Get the name of the field
FieldName = Filler.GetFieldName(i)
'Get the value of the corresponding control in the Access form
'You may need to adjust this line depending on the naming convention of your controls
FieldValue = Me.Controls(FieldName).Value
'Set the value of the field in the PDF template
Filler.SetFieldValue i, FieldValue
Next i
'Save the PDF file with the filled data
If Filler.SaveFile(OutputFile) <> 0 Then
MsgBox "Failed to save the PDF file.", vbCritical
Exit Function
End If
'Close the PDF template file
Filler.CloseFile
'Release the CutePDF Form Filler object
Set Filler = Nothing
'Return True if successful
CreatePDF = True
End Function
The following table summarizes the parameters and return value of the CreatePDF
function:
Parameter | Type | Description |
---|---|---|
TemplateFile | String | The file name and path of the PDF template file |
OutputFile | String | The file name and path of the output PDF file |
Return Value | Boolean | True if the function succeeds, False otherwise |
To use this function, you can add a button to your Access form and use the following code in the button’s Click
event:
'Call the CreatePDF function with the desired parameters
If CreatePDF("C:\PDF\Template.pdf", "C:\PDF\Output.pdf") Then
'Open the output PDF file
Application.FollowHyperlink "C:\PDF\Output.pdf"
Else
'Display an error message
MsgBox "Failed to create the fillable PDF.", vbExclamation
End If
This code will create a fillable PDF from the data in the Access form, save it as C:\PDF\Output.pdf
, and open it in the default PDF viewer. You can modify the file names and paths as needed.