473,396 Members | 1,858 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,396 software developers and data experts.

VBA - Loop through query and email reports

I'm a novice with VBA in Access and I have ran into a problem. If someone has some ideas I would appreciate it.

I have a list of managers in the "tblReportsTo" table (reportsTo is the field). I need to loop through this table, grabbing data from the "tbl5ManagerApproval" table, using the query "qry5MgrAppv" and generate a report(rpt5MgrApporval)which is then emailed to that manger.

What I have for code is below:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command58_Click()
  2. On Error GoTo Exit_Command58_Click
  3.  
  4. Dim rs As Recordset
  5. Set rs = CurrentDb.OpenRecordset("tblReportsTo") 'table
  6. Dim stDocName As String
  7. Dim strSQL As String
  8.  
  9. stDocName = "rpt5MgrApproval"
  10.  
  11.     DoCmd.SetWarnings False
  12.  
  13.     rs.MoveFirst
  14.     Do While Not rs.EOF
  15.  
  16.     strSQL = "SELECT * FROM tblMgrApproval WHERE reportsto= """ & rs!reportsto & """"
  17.  
  18.     DoCmd.SendObject acReport, stDocName, "PdfFormat(*.pdf)", rs!emailAddress, "", "", "Manager Approval", "", True, """"""
  19.     rs.MoveNext
  20.     Loop
  21.  
  22.     rs.Close
  23.     Set rs = Nothing
  24.     MsgBox "Reports Completed", vbOKOnly, "Month End PTO"
  25.  
  26. Exit_Command58_Click:
  27.     If MsgBox("Do you want to cancel the run?", vbQuestion Or vbYesNo) = vbYes Then
  28.         Exit Sub
  29.     Else
  30.         Resume Next
  31.     End If
  32. End Sub
Mar 7 '14 #1
1 2199
jimatqsi
1,271 Expert 1GB
I work in Access 2003 and 2007. It could be there are other ways to do this in the newer versions. But here are the issues I have to deal with to do what you are doing.

Create a pdf to attach. I do that either by designing the report to go to a specific printer, which is a .pdf printer. Depending on the .pdf driver you use, the pdf file created may be a common name (same every time) or it may vary. You'll want to use one that can be configured to not ask any questions during the pdf creation. I use the Bullzip driver.

If you know the name of the file that will created, simple. If not, you will have to loop through the file names in the folder that will be used (using Dir() command) to find the file name to be attached to your mail.

If you cannot design your report to use a specific pdf printer, perhaps because people use the report under other circumstances, then you have add some logic to save the current system default printer, change the default printer to your pdf printer, print the report, and then change the system default printer back.

So there's a lot of unknowns for me here, and I don't want to go into too much detail without knowing what your situation is. If you could fill in some greater detail, I or someone else here can give more help.

Jim
Mar 8 '14 #2

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

Similar topics

4
by: Iain | last post by:
Hello. I'm new to the XML lark, I've got a script to display some RSS feeds on my ASP pages, but I can't work out how to just display the first three... My XSL stylesheet looks like this... can...
2
by: John | last post by:
I two tables one of real estate properties and the other is a table of tenants. The Tenants table has a PropertyIndex field which ties the tenants to the propertys. I have a query that lists the...
5
by: Davey | last post by:
I have a database that books appointments for consultants, and included in this is a report which shows the details of an appointment. This is currently printed and faxed to the consultant. Is...
1
by: Scott Reynolds | last post by:
Hello! I am developing a scheduled (daily) email reports system. The report contains results from a database, based on subscriber definied keywords. I have seen similar system often used on...
2
by: Glamdring | last post by:
I have a text file that has the following format. blah blah blah sfpaaa "Control Unit" blah blah blah
7
by: odysseyphotography | last post by:
A friend would like to have a signup form on his site. Anyone that signs up will be entered into a database and automatically sent an email report. This much I can do! However, he'd then like...
3
by: DAHMB | last post by:
I have a report called rptCarSheet based on a Query called qryCombinedCarAbsentee. In the report I have the following fields , , , , I would like to limit the fields to only show the value if the ...
3
benchpolo
by: benchpolo | last post by:
I have a data table that contains STATUS and ADJCODE. I need to write s SQL query that counts records by STATUS and ADJCODE and send an email to a group of people with result of the counts. I...
5
by: CoolC401 | last post by:
I work for a company with strict lockdown on how our computers are configured. So, add-ins or any new installations are impossible. The following is my dilemma. I created almost 60 different...
3
by: hueffmea | last post by:
Context: I'm in a posiiton where there is a master spreadsheet. Everytime a change needs to be made we have to make the same change many times on multiple tabs and reports. I want to convert the...
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: 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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.