Need help with export report VBA (1 Viewer)

gojets1721

Registered User.
Local time
Today, 07:30
Joined
Jun 11, 2019
Messages
429
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?


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
 

Minty

AWF VIP
Local time
Today, 14:30
Joined
Jul 26, 2013
Messages
10,354
Add a Debug.Print FileName before the output line and see what you get in the immediate window?

What error are you getting?
 

gojets1721

Registered User.
Local time
Today, 07:30
Joined
Jun 11, 2019
Messages
429
2501....I just figured it out though. I had my label printer set as default printer and this caused it. My mistake!
 

Users who are viewing this thread

Top Bottom