【问题标题】:exporting to pdf from an access report with a name from the data从具有数据名称的访问报告中导出为 pdf
【发布时间】:2013-12-05 07:43:10
【问题描述】:

我想从 Access 报告导出为 pdf,其名称由报告中的数据控制。

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

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

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

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

【问题讨论】:

  • 嗨,克里斯,我现在收到 2501 错误,并且正在取消输出操作。我应该以某种方式将字符串链接到数据吗?
  • stritem 和 strcont 填充在哪里?

标签: vba ms-access pdf


【解决方案1】:

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

strReportName = stritem + strcont + ".pdf"

strReportName = strItem & strcont & ".pdf"

我认为你在底部有它...

编辑:

构建它

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

那就用吧

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

【讨论】:

  • HI BMO 我改变了这个,虽然它没有返回错误,但它仍然将文件保存为 _.pdf。我认为它没有看到数据的值。你知道如何让它看到它们吗?欢呼西蒙
  • DoCmd.OutputTo acOutputReport, "", acFormatPDF, myPath & strReportName, False'strReportName 变量上设置断点。当我重新阅读您的代码时,stritemstrcont 是如何填充的?没有作业,这可以解释为什么它是空白的。
  • stritem 和 strcont 都是 ""。如何给它们赋值?
  • 这取决于它们代表什么。如果从其他函数调用ouputpdf(),您可能需要使用参数“传入”该值。请参阅编辑后的答案。
  • outputpdf() 是 srand 单独的,除非我将从访问中的宏运行它。这行得通吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多