473,386 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Ability to Print a User Filtered Sub-Report

I have built a kiosk type setup within MS Access 2013 using VBA to Maximize the screen so users cannot click on the All Access Objects, ribbon, tools, INCLUDING the print button.

They exclusively fill out sub-forms created within a tabbed Form. These sub-forms feed to reports that I use VBA buttons to print out, however it prints out the ENTIRE form. Users are using right-click on forms, using a text filter to get the info they need from the report, and pressing my print button that is printing the ENTIRE form. What VBA code do I need to use to print EXACTLY what they are seeing in the sub-form after they have filtered it.
Aug 22 '17 #1

✓ answered by NeoPa

Brohagen:
This causes the report to ONLY show that date with those students under it. I need a button now to print that.
In that case it may help to know that when a filter is applied to a Form or Report object then that object has its .Filter property updated to reflect the filtering.

Also, when using the DoCmd.OpenReport() procedure there is a parameter called WhereCondition that can be used to filter the Report. This property expects a string of the same format as found in the .Filter property.

Thus, your code would probably look something like :
Expand|Select|Wrap|Line Numbers
  1. With Me
  2.     Call DoCmd.OpenReport(ReportName:=.Name, WhereCondition:=.Filter)
  3. End With

9 3669
PhilOfWalton
1,430 Expert 1GB
Have you created a Report based on the data in your Subform?

Phil
Aug 22 '17 #2
Yes. One tab contains all the Subforms the users completes. Another tab contains all the Reports with data from the Subforms. We use it for an Orientation class. The forms allow the users to add students to classes on certain dates. The user then click on a tab that contains the Report with all the students grouped by the date of orientation. Users are right clicking on the dates, and using a text filter so the report only shows students for a certain date. I need a button they can click to print that view or filtered report. My current VBA button only prints the ENTIRE unfiltered report.
Aug 23 '17 #3
PhilOfWalton
1,430 Expert 1GB
So what is the Record Source for the subform and what is the filter and how are you applying it.

Basically the Record Source for the Report and Subform should be the same, and then you apply the same filter to it.

On your button you will have some code like
Expand|Select|Wrap|Line Numbers
  1. Private Sub CmdPrint_Click()
  2.  
  3.     Dim strWhere As String
  4.  
  5.     strWhere = ' This is the bit that needs sorting out
  6.     DoCmd.OpenReport "MyReport", acViewPreview, , strWhere
  7.     End If
  8.  
  9. End Sub
  10.  
So we need to know how the filter for the Subform is obtained, and the strWhere will probably be the same.

Phil
Aug 23 '17 #4
Sorry. Slightly confused. Both the report and form were built from a query named "Orientation_Info_qry". Is that what you are asking?
Aug 24 '17 #5
NeoPa
32,556 Expert Mod 16PB
Hi Brohagen.

You may notice, when working with Access and other Office applications too, that many items have properties. Forms, Reports, etc, and even the Controls and Sections on these objects, have a whole bunch of properties that can be seen when the Properties Pane is open (It's a must to have the Properties Pane open while doing any designing).

When you look at these objects that you're discussing, one of the properties, that's common to both, is called Record Source. From the code it's referred to as .RecordSource. The value in there is what Phil's asking about.
Aug 24 '17 #6
Yes I got that. I currently have a button on the Report that prints the report:
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenReport "rpt_Orientation_Report1", acViewNormal
I understand I can update the button VBA to print out a filtered view of the Report.

However, users are looking at the entire report, right clicking on a certain date, and applying their own Text Filter directly to the Report. After they have done that they click the button and it prints out the entire report.

I am not applying the filters. Users are directly on the Report. If you open a Report in MS ACCESS you can right click on date or string, and apply a filter to it. For example, again with the Orientation classes; there are students grouped by class date. There may be 5 dates with up to 30 students under each date. Users are right clicking on a date and using a "Equals '15 Sept 17'" string filter. This causes the report to ONLY show that date with those students under it. I need a button now to print that.
Aug 28 '17 #7
NeoPa
32,556 Expert Mod 16PB
Brohagen:
This causes the report to ONLY show that date with those students under it. I need a button now to print that.
In that case it may help to know that when a filter is applied to a Form or Report object then that object has its .Filter property updated to reflect the filtering.

Also, when using the DoCmd.OpenReport() procedure there is a parameter called WhereCondition that can be used to filter the Report. This property expects a string of the same format as found in the .Filter property.

Thus, your code would probably look something like :
Expand|Select|Wrap|Line Numbers
  1. With Me
  2.     Call DoCmd.OpenReport(ReportName:=.Name, WhereCondition:=.Filter)
  3. End With
Aug 28 '17 #8
YES! This is the answer! Thank you NeoPa. My VBA is novice at best but you took my situation and delivered. I've been Googling for months for the answer. Much appreciated.
Aug 28 '17 #9
NeoPa
32,556 Expert Mod 16PB
Always a pleasure.

A very similar situation happened to me on 19th October 2006 (No I didn't need to look it up). I've been posting here ever since.
Aug 28 '17 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Downstreamer | last post by:
Design is as follows: A form for the user to input criteria to be used as the where part of the report's recordsource. This includes a multiselect list box as part of the criteria selection. ...
7
by: Ellen Manning | last post by:
I've got an A2K report showing students and their costs. Student info is in the main report and costs are in a subreport for each student. The user inputs the program desired then only those...
0
by: Mbishr | last post by:
i add a print button to print the report and the on demand Subreport crystal i try this code in the button crReportDocumentForex.PrintToPrinter(1, False, 1, 99) but it print the main report...
25
by: hjozinovic | last post by:
Hi! I have a MainForm and a SubForm on it. They're linked and can be filtered, sorted etc... I designed MainReport and SubReport that should match filter and sort criteria from MainForm and...
0
by: youngac | last post by:
I created a report containing a subreport on an XP Pro machine running Access 2003 (using 2000 format for the database) . It is a student report card. The main report contains the student name etc....
1
by: KADANS | last post by:
Hello, I'm an technical designer, trying to get information out of a database (access2003). Recently my company has installed an new drawingprogramma, one which has links with a database. So...
0
by: Whodat! | last post by:
I am sure that this has been hashed and rehashed but I am unable to find an answer to my question. I have a report that contains multiple subreports. The subreports may or may not contain data to...
0
by: Ang | last post by:
Hi all, I'm going to print out a user list, which some users has purchase sth and some users has not. Therefore I need to print a subreport if the user has purchase, no subreport when the...
28
Brilstern
by: Brilstern | last post by:
Ok, I have a report that is opened up with a filter to a certain person's Equipment Custody Receipt card(ECR). Within this report are two subreports that are linked to the master field on the...
52
by: eye707 | last post by:
I created a form to choose records by last name. After selecting the name with a combo box, I want the command button to open a report with just that record (or those records) showing. When it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.