简体   繁体   中英

Access VBA for table content as export file Path

i am using the code below to output a form in PDF to folder :\\Completions Tracker\\Drawings and it works ok, but i would like to set the filepath to refer to a table, so it can be changed by an admin person, when at different project, instead of having to change the VBA code each time.

I would like to change the fixed file path string to refer to table data instead [SettingDrawingFilePathTbl]![Drawing_FilePath].text but i get a debug when i change the code, any help would be great

Private Sub Command170_Click()
'------Print RFIRegisterInputF form, save input data and close form---------

DoCmd.OutputTo acOutputForm, "RFIRegisterInputF", acFormatPDF, "E:\Completions Tracker\Drawings" & [Forms]![RFIRegisterInputF]![Query_ID] & Format(Date, "ddmmyy") & ".pdf", True

DoCmd.Close acForm, "RFIRegisterInputF", acSaveYes

Use a table to hold the document name (ObjectName) and the corresponding path:

Private Sub Command170_Click()

    '------Print RFIRegisterInputF form, save input data and close form---------
    Const ObjectName As String = "RFIRegisterInputF"

    Dim OutputFile As String

    OutputFile = DLookup("[Path]", "[TableName]", "ObjectName = '" & ObjectName & "'") & _
        [Forms]![RFIRegisterInputF]![Query_ID] & Format(Date, "ddmmyy") & ".pdf"

    DoCmd.OutputTo acOutputForm, ObjectName, acFormatPDF, OutputFile, True
    DoCmd.Close acForm, ObjectName, acSaveYes

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM