【问题标题】:Access VBA to Pass Parameter To Report Based On Query访问 VBA 以将参数传递给基于查询的报告
【发布时间】:2016-12-27 22:23:07
【问题描述】:

我接近语法准确,只是一个大问题!

我从输入框中捕获的用户 ID 没有被传递到报告中,所以我必须输入用户 ID两次

为了达到这个目的需要改变什么?

Public Function userProd() As Integer
Dim userID As String, saveloc As String, filename As String, reportname As String

'Report Name
reportname = "rpt_UserProduction"

'Setting Save location
saveloc = "C:\Test\"

'Setting filename
filename = "userProd "

'Getting User ID To Process
userID = InputBox("Enter User ID:", "VBA InputBox Function")

'Putting together full save location
saveloc = saveloc + filename + userID + ".pdf"

If userID = "" Then
    'Do Nothing and Stop Processing
    Exit Function
Else
    If IsNumeric(userID) Then
        'Preview Report
        DoCmd.OpenReport reportname, acViewPreview, , "User_ID=" & userID

        'Save As PDF
        DoCmd.OutputTo acOutputReport, reportname, acFormatPDF, saveloc, True

        'Close Report
        DoCmd.Close acReport, reportname
    End If
End If

End Function

【问题讨论】:

  • Return 语句与GoSub 一起使用,您可能的意思是使用Exit Function
  • @ThunderFrame - 很好地抓住了那个语法错误。

标签: ms-access vba report ms-access-2013


【解决方案1】:

User_ID 字段是包含数字的文本字段吗?如果是这样,您需要在过滤器中添加单引号。 ...“用户 ID ='”& 用户 ID 和“'”。如果不是文本,是记录太多还是不够?报表加载时是否应用了另一个过滤器,或者在导致过滤器无法按预期工作的基础报表记录源中?

【讨论】:

    【解决方案2】:

    如果“两次”表示一次用于输入框,一次用于报告,则您的 where 条件中的 "User_ID=" 要么拼写错误,要么从您用作报告来源的查询中排除。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-06-11
      • 2014-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多