vba 从具有数据名称的访问报告导出为 pdf

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20394194/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 17:21:03  来源:igfitidea点击:

exporting to pdf from an access report with a name from the data

vbams-accesspdf

提问by user3069120

I am wanting to export from an Access report to a pdf who name is governed by the data within the report.

我想从 Access 报告导出到 pdf,其名称由报告中的数据管理。

I have created the code below but it is only saving the file as _.pdfand not the values I want.

我已经创建了下面的代码,但它只是将文件保存为_.pdf我想要的值而不是我想要的值。

I have the report open when ruinning this. It looks as though the data from the report isnt coming through to the code but I'm not sure how and if this is correct.

我在破坏这个时打开了报告。看起来报告中的数据没有传递到代码中,但我不确定如何以及是否正确。

Could someone help me in as plain english as possible. Many thanks

有人可以用尽可能简单的英语帮助我。非常感谢

Sub outputpdf()

    Dim myPath As String
    Dim strReportName As String
    Dim stritem As String
    Dim strcont As String
    Dim strid As String
    Dim struniq As String

    DoCmd.OpenReport "outputreport", acViewPreview

    myPath = "D:\simon\test\"

    strReportName = stritem + strcont + ".pdf"
    'strReportName = Item + contract_number + "_"+ ".pdf"

    DoCmd.OutputTo acOutputReport, "", acFormatPDF, myPath & strReportName, False

    DoCmd.Close acReport, "outputreport"

End Sub

回答by Bmo

Access and VBA concatenation use the &operator and not +like C languages.

Access 和 VBA 连接使用&运算符而不是+像 C 语言。

strReportName = stritem + strcont + ".pdf"

To

strReportName = strItem & strcont & ".pdf"

You have it right in the bottom part, I think...

你在底部有它,我想......

Edit:

编辑:

build it

建造它

Sub ObjectBuilder()
Dim item As String, cont As String

item = InputBox("Enter Item", "Item", "12345")
cont = InputBox("Enter Container?", "Container", "Shipping Crate")

OutputPdf item, cont

End Sub

Then use it

然后使用它

Sub OutputPdf(item As String, cont As String)
'your code
 strItem = item
 strCont = cont
End Sub