Link to home
Start Free TrialLog in
Avatar of D J
D JFlag for United States of America

asked on

MS Access How can I add a relative path to my VBA PDF output that will work for most Windows computers?

Is there a relative path I can add to the VBA below to dump the PDF into the Documents or My Documents folder in a variety of Windows OS's?

If Len(where) > 0 Then
    where = Left(where, Len(where) - 1)
    DoCmd.OpenReport "rpt_SW_Report_By_H", acViewPreview, , "lc_craftsid IN (" & where & ")", acHidden
    DoCmd.OutputTo acOutputReport, "rpt_SW_Report_By_H", acFormatPDF, "C:\Test\rpt_SW_Report_By_H.pdf", True
    End If
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Norie
Norie

Perhaps.
Dim strDocsPath As String
Dim strRptName As String

    strRptName = "rpt_SW_Report_By_H"

    strDocsPath = CreateObject("WScript.Shell").SpecialFolders("MyDocuments")

    DoCmd.OutputTo acOutputReport, strRptName, acFormatPDF, strDocsPath & "\" & strRptName & ".pdf", True

Open in new window

correction on typo

Dim xFolder As String
 xFolder = Environ("UserProfile") & "\Documents"
 If Dir(xFolder, vbDirectory) = "" Then
     xFolder = Environ("UserProfile") & "\My Documents"
 End If

 DoCmd.OutputTo acOutputReport, "rpt_SW_Report_By_H", acFormatPDF, xFolder & "\rpt_SW_Report_By_H.pdf", True
Avatar of D J

ASKER

Worked perfectly!