2016-12-27 4 views
0

構文が正確で、1つの大きな問題があります。入力に

私は入力ボックスからキャプチャしていますユーザー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

入力ボックスの場合は1回、レポートの場合は1回を意味する場合は、どこの条件の"User_ID="がスペルの誤りか、レポートのソースとして使用するクエリから除外されます。

関連する問題