问题
My apologies if this is an easy/straightforward solution, but I am new to Access, and I have been having some problems with my reports.
I have created a report template which I want to open a single page report based on a specific IDENT NO. All of the fields in the report are then generated from the associated IDENT NO. As it currently stands, when I open the report, it will create a single page report for each ID number in the Report Data table when opened.
Instead, when the user is attempting to open the report, I want it to prompt the user to enter the identification number of the specific report they are looking for so that it only opens that single individual 1 page report associated with the entered IDENT NO.
Any Ideas on how I could achieve this filtering?
回答1:
You can display an InputBox for the user to insert the ID and then open and filter the report.
Dim id As String
id = InputBox("Enter the identification number:", "YourInputBoxTitle")
'if a value was entered, open and filter report
If Len(Trim(id)) > 0 Then
DoCmd.OpenReport "ReportName", acViewPreview, , "[IDENT NO] = " & id, acWindowNormal
End If
回答2:
An alternative to using InputBox
is to used a "parameter query" (documentation here)
Anywhere in a query criteria or report design view you may enter [IdentNoVariable]
and a dialog box will appear (when the report or query is run) asking you to "Enter Parameter Value" for IdentNoVariable.
For example, if you wanted to restrict an ID # during a query (say the query that your report calls):
The dialog box seen appeared upon running the query and has the text of the variable seen in the query criteria. This same thing can be done in a report by entering [IdentNoVariable]
into the part of the report where the entered value is desired.
来源:https://stackoverflow.com/questions/43741102/filter-a-report-based-on-user-input-microsoft-access