473,386 Members | 1,738 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.

How to Export a report to .PDF to separate sheets based on numbers

anoble1
245 128KB
I currently have a report that runs in MS Access.
The reports gives totals on parts by a User (that have a unique number)
Example User 075 has 7 pages of items, then the next user etc.

Is there a way to have access break up the report when it moves to the next User or number? Instead of having 1 big report have it break it up into Each user has their own report?
Sep 16 '14 #1

✓ answered by twinnyfo

I see. Lets try something similar to this:

Make a copy of the query behind your report. Name the copy "qryReportUsers" or something similar (you can also modify this query so that it only returns the users and groups by User. Modify the other query to use as the criteria for your User Field the following:

Expand|Select|Wrap|Line Numbers
  1. WHERE User = TempVars.Item("User")
This is a Temporary global variable that Access introduced in 2007. You will see how it is used below. If you have an earlier version of Access, we can easily over come this, but we will assume 2007 and later for now.

Below is the very basics of what you will want to do, and hopefully will point you in the right direction of where you want to go with this.

Expand|Select|Wrap|Line Numbers
  1. Private Sub ExportReports()
  2.     Dim db As Database
  3.     Dim rst As Recordset
  4.     Dim strSQL As String
  5.     Dim strPath As String
  6.     strPath = "C:\YourPath\YourFolder\"
  7.     Set db = CurrentDb()
  8.     strSQL = "SELECT User " & _
  9.         "FROM qryReportUsers " & _
  10.         "GROUP BY User;"
  11.     Set rst = db.OpenRecordset(strSQL, dbOpenDynaset)
  12.     If Not rst.RecordCount = 0 Then
  13.         rst.MoveFirst
  14.         Do While Not rst.EOF
  15.             TempVars.Add "User", rst!User
  16.             DoCmd.OutputTo acOutputReport, _
  17.                 "YourReport Name", acFormatPDF, _
  18.                 strPath & "YourReport" & rst!User & ".pdf"
  19.             rst.MoveNext
  20.         Loop
  21.     End If
  22.     rst.Close
  23.     db.Close
  24.     Set rst = Nothing
  25.     Set db = Nothing
  26. End Sub
Note that Line 6 is the folder where you want to save these PDF files.

Lines 8-10 refer to the query we modified earlier, but also groups, just in case you did not.

In lines 16-18, we are exporting the PDF. Rmeember, because we added the criteria User = TempVars.Item("User"), the Report should only return those pages that apply to that particular User. It also saves the Report with the identifier for the User (there are many ways to play with this).

I hope this gets you pointed in the right direction.

7 1322
twinnyfo
3,653 Expert Mod 2GB
anoble1,

Yes, this is very possible. There may be other ways, but the two most likely would be to 1) execute the report, applying a filter to it (based on the User), and saving each report as an individual report; or 2) modifying the Report's query so that it uses the User in its criteria (either through a Global variable or TempVars Variable) and cycling through the Users, assigning the User to the Variable and running the Report with this new query and saving to PDF.

Option 1 is probably simpler--it just depends on how you have other things set up in your project.

Standing by for further assistance, as needed.....
Sep 16 '14 #2
anoble1
245 128KB
Yeah, thought about that. But was wondering on if it could be done automated. I would have a whole lot of reports if I broke them up by user. Wonder if there would be some VBA that could go through and export based on the number or person?
Sep 16 '14 #3
twinnyfo
3,653 Expert Mod 2GB
Yes, both methods would be automated. What method are you using for exporting your Report right now? We can use that for a launching pad to where you want to go....
Sep 16 '14 #4
anoble1
245 128KB
I have no VBA right now. I will probably write something to export to a PDF file later today and tomorrow. Right now I am exporting the master and Extracting the pages manually.
Sep 16 '14 #5
twinnyfo
3,653 Expert Mod 2GB
I see. Lets try something similar to this:

Make a copy of the query behind your report. Name the copy "qryReportUsers" or something similar (you can also modify this query so that it only returns the users and groups by User. Modify the other query to use as the criteria for your User Field the following:

Expand|Select|Wrap|Line Numbers
  1. WHERE User = TempVars.Item("User")
This is a Temporary global variable that Access introduced in 2007. You will see how it is used below. If you have an earlier version of Access, we can easily over come this, but we will assume 2007 and later for now.

Below is the very basics of what you will want to do, and hopefully will point you in the right direction of where you want to go with this.

Expand|Select|Wrap|Line Numbers
  1. Private Sub ExportReports()
  2.     Dim db As Database
  3.     Dim rst As Recordset
  4.     Dim strSQL As String
  5.     Dim strPath As String
  6.     strPath = "C:\YourPath\YourFolder\"
  7.     Set db = CurrentDb()
  8.     strSQL = "SELECT User " & _
  9.         "FROM qryReportUsers " & _
  10.         "GROUP BY User;"
  11.     Set rst = db.OpenRecordset(strSQL, dbOpenDynaset)
  12.     If Not rst.RecordCount = 0 Then
  13.         rst.MoveFirst
  14.         Do While Not rst.EOF
  15.             TempVars.Add "User", rst!User
  16.             DoCmd.OutputTo acOutputReport, _
  17.                 "YourReport Name", acFormatPDF, _
  18.                 strPath & "YourReport" & rst!User & ".pdf"
  19.             rst.MoveNext
  20.         Loop
  21.     End If
  22.     rst.Close
  23.     db.Close
  24.     Set rst = Nothing
  25.     Set db = Nothing
  26. End Sub
Note that Line 6 is the folder where you want to save these PDF files.

Lines 8-10 refer to the query we modified earlier, but also groups, just in case you did not.

In lines 16-18, we are exporting the PDF. Rmeember, because we added the criteria User = TempVars.Item("User"), the Report should only return those pages that apply to that particular User. It also saves the Report with the identifier for the User (there are many ways to play with this).

I hope this gets you pointed in the right direction.
Sep 16 '14 #6
anoble1
245 128KB
I think I can do something with that. Let me work with that info!
Sep 16 '14 #7
twinnyfo
3,653 Expert Mod 2GB
Let us know how you get along!
Sep 16 '14 #8

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

Similar topics

2
by: Matt. | last post by:
Hi All! Is it possible to export an Access Report? Not the report that is produced when the report is run, but the actual framework, or source, of the report. I'm trying to debug a report I...
1
by: Majstor | last post by:
Does anybody know how to export Report in Word, Excel or HTML with pictures (Access 2000)? I don't use snapshot format.
2
by: B Garner | last post by:
Hi all Help please. I would like to automate the printing of a report. The report actually is a single page and prints a label. I would like to be able to print the report multiple times...
0
by: moshe_n | last post by:
Hello I try to export report from access 2000 by mail and always i get the massege " the report can not open the mail application" I use the Lotus notes application , noach,
0
by: Mariana | last post by:
Hello, I am exporting reports in pdf format from .net 2005 . The export is working fine; however the user values of stored procedure parameters does not show in the report. What do I need to do in...
1
by: ttfitz | last post by:
I have an application developed in Access 2000, to be distributed as an MDE. For those folks without Access, they install the free Access 2007 runtime. For the most part, this seems to be working...
7
by: barrhaven01 | last post by:
Hi there, I was wondering if anyone could suggest a method using only access ( ie no additional applications) to batch export reports to excel. Basically i have a report with a query for its...
0
by: nebula53 | last post by:
Hi, 1 - I created search criteria based in one input ( contract status “ Combo box”) I need to add to it another criteria (Vendor Number “ text Box” ) ( the number will be entered manually ) ...
2
by: ghiey | last post by:
hi to all, i have searched for a solution regarding exporting access 2007 reports to excel file. i have converted to access 2007 my database from access 2003. i guess microsoft omitted the ease...
5
by: jbrown8253 | last post by:
Microsoft Access 2007 Export Report for each record within a recordset I am attempting to click a button on a form that will export a report that is unique to each record. I created a query that...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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.