How do I open an MS-Access report with a subset of the recordsource data? - vba

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.

Options for dynamic filtering of report dataset:
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
manually open report in design view and set the Filter property then switch report to print preview then print
code (macro or VBA) applies filter when report opens by referencing control on form, example VBA: DoCmd.OpenReport "report name", , , "ControlNumber='" & Me.cbxCN & "'"

Related

Open Report Based on Multiple Combo Box Selections (Access, VBA)

I have a set of reports stored in Access, and I am trying to generate a specific report based on multiple combo box selections and a "run report" button on a form.
For this example, Combo Box 1 = Location, and Combo Box 2 = Report Type.
Suppose I choose Toronto from Location, and Sales from Report Type. This means I'd like to generate the Sales Report for Toronto.
I have two issues - 1 major and 1 minor.
Major issue: I can currently only generate reports based on 1 combo box selection. My code is as follows:
DoCmd.OpenReport Forms!Form1!Loc, acViewPreview, , "[Loc]='Toronto'"
In order for this to work, I would need to have my sales report named as "Toronto". For the purpose of checking the code, I did that and it worked. However, I am trying to use multiple combo boxes and need more complex naming for my reports. How can I make it so that the code pulls the selection from multiple combo boxes and generates the corresponding report?
Minor issue:
When running the report, I get a popup message that asks me to specify location again:
location popup
How can I prevent this popup from appearing?
Any help is greatly appreciated!!
Are you using a query ? is the best option to do that.
that box that pops up is because you are trying to open the report but the data to the field "loc" is missing.

Run report based on a user's Sort on a Form

I have several reports that populate off the Form below. I would like to add a function for when a user uses the column Sort drop downs, the reports only look at the visible records.
So for example a report run while viewing the window below would return only files where the customer is named Placeholder.
Is there a simple way to do this with a macro or query without resorting to VBA?
This macro ended up working well.

Select Query Doesn't Show All Results

I have a combobox on a subform (ProgramSubform) in Access that's supposed to list report years for a project from a table (Program). Most projects have more than one report year, but the combobox always brings only 2014.
For example, the dropdown for project 5278 should be:
2012
2013
2014
Instead, it's only
2014
This is the select query that I'm using. It was working properly before, but I don't know when it stopped working; no changes were made to the tables or subform.
SELECT Program.ReportYear
FROM Program
WHERE (((Program.ProjNo)='ProgramSubform.ProjNo'));
Any idea why it might have stopped working, or how to fix it?
This WHERE clause asks Access to limit the rows returned by the query to those whose ProjNo values match the text string 'ProgramSubform.ProjNo'
WHERE (((Program.ProjNo)='ProgramSubform.ProjNo'))
But ProgramSubform.ProjNo is actually a data control on a subform. So don't include quotes around its name.
You can use a reference to the control via the parent form in the Forms collection:
WHERE Program.ProjNo= Forms![Parent Form]!ProgramSubform!ProjNo
If you're building the SELECT statement with VBA code in the form, you can include the control's value instead of its name:
"WHERE Program.ProjNo=" & Me!ProgramSubform!ProjNo.Value
"WHERE Program.ProjNo='" & Me!ProgramSubform!ProjNo.Value & "'"
Use the first version for a numeric field or the second for text.
Notes:
I assumed ProgramSubform is the name of the subform control. It could also be the name of the form contained in that subform control. But those names can be different. So make sure you used the subform control name.
This query is used as the Row Source for a combo box on the subform. You want to update the values displayed in the combo whenever ProjNo.Value changes. You can accomplish that by calling the combo's Requery method from the After Update event of ProjNo.
Pay attention to the brackets, you have three before Program.ProjNo on WHERE clause, but you only need two brackets (in this case) you should use:
SELECT Program.ReportYear
FROM Program
WHERE ((Program.ProjNo='ProgramSubform.ProjNo'));
anyway you will prefer:
SELECT Program.ReportYear
FROM Program
WHERE Program.ProjNo='ProgramSubform.ProjNo';

SSRS Printing Multiple of the Same Invoice

I am developing a "Proof of Delivery" form for my organization using SSRS Report Builder on a SQL Server 2008R2 Database. I am having difficulties printing multiple copies of the same form with a different watermark (Driver Copy/Customer Copy). All of the same info is on both forms. I read about using page breaks and copying the original tablix so there are two tables on one development page. This works for creating those forms. However, when I print, all of the "Driver Copy" form print first then "Customer Copy".
The Following is an example of the print order:
Invoice Number 12345 Driver Copy
Invoice Number 67890 Driver Copy
Invoice Number 12345 Customer Copy
Invoice Number 67890 Customer Copy
I would like to print like the following:
Invoice Number 12345 Driver Copy
Invoice Number 12345 Customer Copy
Invoice Number 67890 Driver Copy
Invoice Number 67890 Customer Copy
Collating isn't the huge of an ordeal until we have 200+ forms to print. Is there any way within Report Builder 3.0 or BIDS for me to achieve this?
BTW, the data source can not be manipulated. However, if there is a way to do this within the query builder, I'm open to it.
Put a "List" Data region on the design surface from the toolbox (BIDS) or insert it from the ribbon (in RS Builder), and then place the two tables on it. Set the grouping for the list item (which is actually a tablix with one cell and a rectangle) to the "invoice number". This will group visually your forms.
You can additionally set a sorting to get back the results in the correct order (driver -> customer copy)
If you want to have page breaks between each instance of the grouping, you can edit the page breaks of your "List" data region.

Substitute one table for another at runtime

I have 9 tables with state information in them. They all have the same field names. I have a Crystal Report that is based on one of them. I want the user to be able to select a state and change the Crystal Report to use that table instead of the one it was based on.I mean when user select text in combo box and then click on "OK" then report show (using only one rpt for all the tables of same fields).
How do I do that in VB.Net?
Could you base the Report on a Stored Procedure and pass in a parameter so the Stored Procedure knows which table you want the data from?
I remember trying to get a Crystal Report (v2005) to switch database source from the one it was designed against and that wasn't easy - every table had the connection details in it if I recall correctly! (maybe changing tables is easier though)
It's not easier but if the tables have the same structure you should be able to do it. But you should create a new Document for it and call SetDataSource for your new table. After this you can set the document as ReportSource to your viewer.