Ms access 访问VBA以根据查询将参数传递到报表
我接近语法准确,只是一个大问题Ms access 访问VBA以根据查询将参数传递到报表,ms-access,vba,report,ms-access-2013,Ms Access,Vba,Report,Ms Access 2013,我接近语法准确,只是一个大问题 我从输入框捕获的用户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 l
我从输入框捕获的用户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
用户ID字段是一个包含数字的文本字段吗?如果是这样,您需要将单引号添加到筛选器。。。“User_ID=”&userId&“”。如果不是文本,你是得到的记录太多还是不够?加载报表时是否应用了另一个筛选器,或者在基础报表记录源中是否存在导致筛选器无法按预期工作的筛选器 如果“两次”表示一次用于输入框,一次用于报告,则where条件中的
“User\u ID=“
拼写错误或从用作报告源的查询中排除。Return语句用于,您可能想使用退出函数@ThunderFrame-很好地抓住了这个语法错误。