将表内容作为导出文件路径

时间:2018-02-15 03:46:08

标签: access-vba filepath

我正在使用下面的代码将PDF中的表单输出到文件夹:\ Completions Tracker \ Drawings并且它工作正常,但我想设置文件路径以引用表,因此可以由管理员更改人,在不同的项目中,而不是每次都必须更改VBA代码。

我想更改固定文件路径字符串以引用表格数据[SettingDrawingFilePathTbl]![Drawing_FilePath].text 但是当我更改代码时,我得到一个调试,任何帮助都会很棒

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

1 个答案:

答案 0 :(得分:0)

使用表格来保存文档名称(ObjectName)和相应的路径:

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