Save form as pdf

rosajen

Registered User.
Local time
Today, 06:49
Joined
Aug 8, 2011
Messages
10
Hi

I'm using access 2007 and I have over 20 forms that are bound to their respective tables. When a save button I made is pressed I want the record to save in the table and the current individual record to save as a pdf in form view. Right now it saves as a record in the table but the pdf saves with all of the records in form view under a single pdf name so I have 40 records in one file. i know that i should make a report and I am totally willing to do that if the report doesnt have to be clicked on or anything to make it save as a pdf. The users know nothing about access so I want it to be just this one button click. Here is what I have to save the forms as pdf. Any help would be appreciated:

Code:
Private Sub Save_Click()
On Error GoTo save_record_Click_Err 'this is the button click
    On Error Resume Next
 
    If IsNull(Me.Person_Performing_the_Work) Then
    MsgBox "Please fill out the person performing work field"
    Cancel = True
    Else
 
    DoCmd.RunCommand acCmdSaveRecord
    If (MacroError <> 0) Then
        Beep
        MsgBox MacroError.Description, vbOKOnly, ""
    End If
 
DoCmd.GoToRecord acActiveDataObject, "Form Name", acLast
 
'this calls the save pdf function below  
SaveToPDF ("Expendable Form")

-------------------------------------------------------

Code:
Public Function SaveToPDF(SrcFile As String)
On Error GoTo SaveToPDF_Err
 
'SrcFile = name of report the function was called from, as generated by Screen.ActiveForm.Name
 
'DestPath = Destination path for PDF file
Dim DestPath As String
 
'DestFile = Destination file name for PDF file
Dim DestFile As String
 
'ShowPdf = launch acrobat and display saved PDF file
Dim ShowPdf As Boolean
 
'Saves the file to specific folder(this is not my real path)
DestPath = "Documents\Practice Save\"
 
'Formats the file name
DestFile = Month(Now) & "_" & Day(Now) & "_" & Year(Now) & "_" & [Manufacturer's S/N] 
 
ShowPdf = False
 
Dim strDestFile As String
strDestFile= DestPath & DestFile & ".pdf"
 
DoCmd.OutputTo acOutputForm, , acFormatPDF, strDestFile, False
SaveToPDF_Exit:
Exit Function
SaveToPDF_Err:
Resume SaveToPDF_Exit
End Function

Thanks!!!
 
Would it not be easier sending it to the default printer with the default printer being the PDF printer?
 
Before you send it to save as a PDF you need to apply a filter to the form.
Filter for what you want to print (current record) and you are all set.
 
But to your original comment, I would advise to create a report (based on the form).
With the push of a button you then open the report for the selcted record and send it to the printer.

I don't remember teh full code for this, but I know I have it in a database at home.
Let me know if you need it.
 
Thanks for replying

I have tried a filter before but it doesn't change the result unfortunately. As for the pdf printer this database can be accessed by over 300 computers so its not practical for me to make sure everyone has the pdf printer as default.

I think I will try the report thanks so much for your help!!!!
 
timf79

Can you advise how to set the filter? I have a control button to email and pdf a record on the form - except it pdf's all the records. I just cant seem to get the filter right so that it just pdf the current record.

Can you help?
thanks
 

Users who are viewing this thread

Back
Top Bottom