How do I open an MS-Access report with a subset of

2019-08-22 21:37发布

问题:

I have a query that produces a recordset that I use for a computer generated invoice that I have created with an MS Access report. The recordset looks something like this (but with hundreds of invoices):

ControlNumber|ShippingAddress|InventoryDescription|...
17-001        123 Fake St     Description A
17-002        145 No addr     Description B
17-003        23456 new st    Description C

I have the report set up so it will generate me separate completely filled out invoices on a different page for every invoice in the system. I don't want to have to hunt through hundreds of them to find the specific one I want to print, though.

I have another MS Access form that the operator uses to select which of these invoices to print with a drop down combo box, and a button. After I use the dropdown to choose which one I want to print (say 17-003), I want to hit the button and have the report pop up with only that one single invoice. How do I tell the report to only show me a subset of that recordset?

I am fine with using existing Access functions or with writing VBA code if necessary, but I would prefer to not default to VBA if possible.

回答1:

Options for dynamic filtering of report dataset:

  1. dynamic parameterized query as the report RecordSource, this can be a popup input or reference to a control on form - I never use dynamic parameterized queries

  2. manually open report in design view and set the Filter property then switch report to print preview then print

  3. code (macro or VBA) applies filter when report opens by referencing control on form, example VBA: DoCmd.OpenReport "report name", , , "ControlNumber='" & Me.cbxCN & "'"