473,385 Members | 2,044 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,385 software developers and data experts.

Microsoft Access 2007 Export Report for each record within a recordset

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 contains the Employer ID numbers that the report should be run for. I am unable to make it work. The report currently runs fine when I enter in the EmployerID number one at a time.

Below are the fields being used:

(BEEmployers) Qry with records that need reports run
(EmployerID) Column within query that contains record ID data that needs passed to report
(Annual) Name of report that needs printed for each record



Expand|Select|Wrap|Line Numbers
  1. Private Sub AnnRptExportAll_Click()
  2. Dim db As DAO.Database
  3. Dim rs As DAO.Recordset
  4. Dim ID As integer
  5.  
  6. Set db = CurrentDb()
  7. Set rs = db.OpenRecordset("BEEmployers")
  8.  
  9. If rs.RecordCount = 0 Then Exit Sub
  10.  
  11.  rs.MoveFirst
  12.   Do Until rs.EOF
  13.    ID = rs![EmployerID]
  14.    DoCmd.OpenReport StDocName, acPreview, , "[employerid]=" & ID
  15.    DoCmd.OutputTo acReport, "Annual", acFormatPDF, "G:\Research\EFR_Export\NONBE\ER_" & ID & ".pdf"
  16.    DoCmd.Close
  17.  
  18.  rs.MoveNext
  19.  Loop
  20.  
  21.  
  22. rs.Close
  23.  
  24. Set rs = Nothing
  25. Set db = Nothing
  26.  
  27. MsgBox ("Completed")
  28.  
  29. End Function
Sep 27 '12 #1
5 2520
Seth Schrock
2,965 Expert 2GB
When you say you are unable to get it to work, what do you mean? Are you getting error messages (if so, what are they), or does it run, but not the way that you want it to (if so, what does happen)?

Also, when you post code, please use the <code/> button.
Sep 27 '12 #2
Currently the code does not run and there are no errors.

I did revise the line below...
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenReport "annual", acPreview, , "[employerid]=" & ID
Sep 27 '12 #3
I fixed it. I needed to change the end Function at the bottom to end sub.
Sep 27 '12 #4
Seth Schrock
2,965 Expert 2GB
Please use the <code/> format when posting code.

If there are no error messages, then the code is running (unless it got disconnected from the button AnnRptExportAll's On_Click event) , but it could be exiting prior to when it is supposed to. Click on the gray area to the left of the
Expand|Select|Wrap|Line Numbers
  1. Set db = CurrentDb()
line. A red dot should appear. Then click your button to trigger the code. The code will stop at the line with the red dot and highlight that line in yellow. Now press F8 to go to the next line. Keep pressing F8 and watch to see when it goes to the
Expand|Select|Wrap|Line Numbers
  1. End Sub
line. I just noticed that your line says
Expand|Select|Wrap|Line Numbers
  1. End Function
That needs to be Sub, not Function. Going through the code in this way will either produce the error or tell us what line of code got executed last.
Sep 27 '12 #5
Seth Schrock
2,965 Expert 2GB
Splended. I just noticed that myself.
Sep 27 '12 #6

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

Similar topics

5
by: Ken Fine | last post by:
Suppose I've built a recordset. I want some code to run for each record in the recordset in a "loop." In ASP VBScript, how would you express the following: For each in next The only...
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: Elaine Shore | last post by:
I have an Access 2000 database where each record has it's own photo stored as an OLE object. I am trying to export a report (of all the records) to HTML format. The data for each record exports...
3
by: larry | last post by:
Hi, Is there a way to calculate the sum of the numbers in each field for each record in the recordset returned from the query? Do I have to use VBScript? Thanks, Larry
1
by: lineah | last post by:
How can J use animated icons or play avi file in microsoft access 12
0
by: =?Utf-8?B?QW15?= | last post by:
I'm currently using Microsoft Office 2007 which includes Access. I have set up a secondary language in my computer since this is required, however I have set the default input language as English...
5
by: quicknk | last post by:
Is there a way in MS Access 2007 to export specific rows out of the specified table? Say I have a database with just 1 table called "contact numbers" and in this table I just have 2 field on is the...
1
by: fifothekid | last post by:
Hi everybody, I made a primitive cost control database system using Microsoft Access 2007 as a front-end (don't ask my why did I use Microsoft Access!!!) and SQL Server 2005 Enterprise as a back-end...
8
by: Jesse Jones | last post by:
I am using Access 2007 and I am a complete ignoramus with this stuff. I have designed a modal login form for my database that is working perfectly. I did this by placing an invisible dlookup...
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...
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: 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
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
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.