Hi,
I'm using access 2007 and I have over 20 forms that I need to save the current record in form view as a pdf every time a new record is entered. The code shown below saves every record in the record source table in one pdf. So in the one pdf file I have maybe 40 records in form view. The code is called from a button click on the form. I need everything to be done from that one button click. The person that is going to be filling out this form has no idea what access is and needs everything to be as simple as possible. The code is below and I worte in comments to try to explain better:
Private Sub Save_Click() 'button on form
On Error GoTo save_record_Click_Err
On Error Resume Next
If IsNull(Me.Signature) Then
MsgBox "Please fill out the Signature field" 'check completed fields
Cancel = True
Else
DoCmd.RunCommand acCmdSaveRecord 'saves as record in table
If (MacroError <> 0) Then
Beep
MsgBox MacroError.Description, vbOKOnly, ""
End If
'Brings up the last saved record which would be the one just entered in
DoCmd.GoToRecord acActiveDataObject, "Form Name", acLast
'Calls function
SaveToPDF ("Form Name")
-------------------------------------------------------
Public Function SaveToPDF(SrcFile As String)
On Error GoTo SaveToPDF_Err
'SrcFile = name of form the function was called from
'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 isn't my real file path)
DestPath = "\My Documents\Practice Save\"
'Formats the file name
DestFile = Month(Now) & "_" & Day(Now) & "_" & Year(Now) & "_" & [Certificate #]
ShowPdf = False
Dim strDestFile As String
strDestFile = DestPath & DestFile & ".pdf"
Me.Filter = "ID=" & Me.ID
Me.FilterOn = True
DoCmd.OutputTo acOutputForm, scrFile, acFormatPDF, strDestFile, False
Me.FilterOn = False
SaveToPDF_Exit:
Exit Function
SaveToPDF_Err:
Resume SaveToPDF_Exit
End Function
I'm not sure what I'm doing wrong but any help would be appreciated Thanks!!