2016-12-27 71 views
0

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

,我从输入框中捕获用户ID,没有被传递到报告,所以我必须要输入用户ID两次
访问VBA将参数传递给基于查询的报表

需要什么,以实现这一目标被改变?

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 
+0

'Return'语句与['GoSub'](https://msdn.microsoft.com/en-us/library/office/gg251648.aspx)一起使用,您可能的意思是使用'Exit Function' 。 – ThunderFrame

+0

@ThunderFrame - 很好地捕捉到这种语法错误。 –

回答

0

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

0

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