Need to change export VBA to let user select folder location

Okay that worked...last issue (I'm sorry). It doesn't seem to be applying the criteria. When I export, it's exporting every entry in the form to PDF when it should be exporting only one. Anything visible from the code that would cause the criteria to not be applied? Here's the code:

Code:
Private Sub btnExportEvent_Click()
    Dim reportName As String
    Dim criteria As String
    Dim fd As Object
    Dim filename As String
 
    reportName = "CompletedForm"
    criteria = "[ComplaintNumber]= " & [Forms]![frmDetails]![ComplaintNumber]

    Set fd = Application.FileDialog(2)
    filename = Me.CustomerLastName & ", " & Me.CustomerFirstName & " " & Format(Me.DateOpened, "m.d.yyyy") & ".pdf"
    With fd
        .InitialFileName = "C:\Users\Public\" & filename
        .Show
    End With
   
    MsgBox filename

    DoCmd.OpenReport reportName, acViewPreview, criteria, acHidden
    DoCmd.OutputTo acOutputReport, reportName, acFormatPDF, filename
    DoCmd.Close acReport, reportName, acSaveNo
End Sub
 
Okay that worked...last issue (I'm sorry). It doesn't seem to be applying the criteria. When I export, it's exporting every entry in the form to PDF when it should be exporting only one. Anything visible from the code that would cause the criteria to not be applied? Here's the code:

Code:
Private Sub btnExportEvent_Click()
    Dim reportName As String
    Dim criteria As String
    Dim fd As Object
    Dim filename As String

    reportName = "CompletedForm"
    criteria = "[ComplaintNumber]= " & [Forms]![frmDetails]![ComplaintNumber]

    Set fd = Application.FileDialog(2)
    filename = Me.CustomerLastName & ", " & Me.CustomerFirstName & " " & Format(Me.DateOpened, "m.d.yyyy") & ".pdf"
    With fd
        .InitialFileName = "C:\Users\Public\" & filename
        .Show
    End With
  
    MsgBox filename

    DoCmd.OpenReport reportName, acViewPreview, criteria, acHidden
    DoCmd.OutputTo acOutputReport, reportName, acFormatPDF, filename
    DoCmd.Close acReport, reportName, acSaveNo
End Sub
Hi. Glad to hear you're making good progress. What data type is "ComplaintNumber?"
 

Users who are viewing this thread

Back
Top Bottom