gojets1721
Registered User.
- Local time
- Today, 14:53
- Joined
- Jun 11, 2019
- Messages
- 430
I've got a command to export an open report to PDF. Below is the code. The debugger is pinpointing the DoCmd.OutputTo line.
Any idea what needs to be fixed?
Any idea what needs to be fixed?
Code:
Private Sub btnExportReport_Click()
On Error GoTo btnExportReport_Click_Err
Dim ReportName As String
Dim fd As Object
Dim filename As String
Dim strReportName As String
strReportName = rptComplaints
Set fd = Application.FileDialog(2)
filename = "Report" & ".pdf"
With fd
.Title = "Save to PDF"
.InitialFileName = "\Documents\" & filename
If .Show = -1 Then
filename = fd.SelectedItems(1)
If InStr(filename, ".") = 0 Then
filename = filename & ".pdf"
ElseIf Right(filename, 4) <> ".pdf" Then
k = InStrRev(filename, ".") - 1
filename = Left(filename, k)
filename = filename & ".pdf"
End If
DoCmd.OutputTo acOutputReport, ReportName, acFormatPDF, filename
MsgBox "Report saved to " & filename
End If
End With
btnExportReport_Click_Exit:
Set fd = Nothing
Exit Sub
btnExportReport_Click_Err:
MsgBox "Error #" & Err.Number & " - " & Err.Description, , "Error"
Resume btnExportReport_Click_Exit
End Sub