473,549 Members | 2,579 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Email a report and attach each record as seperate report

DJRhino1175
221 New Member
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private Sub E_mailExt_Click()
  5.  
  6.     Dim strEMail As String
  7.     Dim oOutlook As Object
  8.     Dim oMail As Object
  9.     Dim strAddr As String
  10.     Dim MyDB As DAO.Database
  11.     Dim rstEMail As DAO.Recordset
  12.     Dim strReportName As String
  13.  
  14.     Set oOutlook = CreateObject("Outlook.Application")
  15.     Set oMail = oOutlook.CreateItem(0)
  16.  
  17.     strReportName = "ES Test Failure"
  18.  
  19.     DoCmd.OutputTo acOutputReport, "ES Test Failure Report", _
  20.         acFormatPDF, "N:\Lab\ES_Test_Failure_Reports" & "\" & strReportName & _
  21.         "-" & Format(Date, "mm-dd-yy") & ".pdf", False, , , acExportQualityPrint
  22.  
  23.     'Retrieve all E-Mail Addressess in tblEMailAddress
  24.     Set MyDB = CurrentDb
  25.     Set rstEMail = MyDB.OpenRecordset("Select * From EXTEMail", _
  26.                     dbOpenSnapshot, dbOpenForwardOnly)
  27.  
  28.     With rstEMail
  29.       Do While Not .EOF
  30.         'Build the Recipients String
  31.         strEMail = strEMail & ![email] & ";"
  32.           .MoveNext
  33.       Loop
  34.     End With
  35.     '--------------------------------------------------
  36.  
  37.     With oMail
  38.       .To = Left$(strEMail, Len(strEMail) - 1)        'Remove Trailing ;
  39.       .Body = "Please review the attached report."
  40.       .Subject = Replace(Replace("ES Test Failure # |1: P/N: |2", "|1", Nz([ID #], "")), "|2", Nz([Part Number], ""))
  41.       .Attachments.Add "N:\Lab\ES_Test_Failure_Reports" _
  42.                         & "\" & strReportName & "-" & Format(Date, "mm-dd-yy") & ".pdf"
  43.  
  44.           .Display
  45.  
  46.     End With
  47.  
  48.     Set oMail = Nothing
  49.     Set oOutlook = Nothing
  50.  
  51.     rstEMail.Close
  52.     Set rstEMail = Nothing
  53.  
  54.     Dim aFile As String
  55.     aFile = "N:\Lab\ES_Test_Failure_Reports\ES Test Failure.pdf"
  56.     If Len(Dir$(aFile)) > 0 Then
  57.          Kill aFile
  58.     End If
  59.  
  60. End Sub
In this case I have more than one record, I need each record exported and attached to an email using the above code.

The code above works good for a single record but not with multiple records.

So my question is: with the above code is it easy enough to add more code to do what I want to do or do I need to filter the form and report and send each one separately?
Jul 30 '19 #1
4 922
twinnyfo
3,653 Recognized Expert Moderator Specialist
DJ,

I haven’t looked in detail at your code, but in general, what you want to do is create a record set that includes both the e-mail address(es) that you want to send the report to, as well as the filtering data specific to that addressee. You cycle through those addressees, and send the Report that is filtered accordingly. There are multiple ways to do this. You can use a global filtering string, you can export the report, filtered appropriately, and named appropriately, then attach that file to an e-mail.

Again, lots of ways to skin this cat. We can talk options with additional details.

Hope this hepps!
Jul 30 '19 #2
DJRhino1175
221 New Member
Thanks for the response Twinn.
After some thought and discussion I was looking at it wrong. They only want to email the current record that is currently shown on the form. So what I need to do is have the output section to be filtered to the current record only.
Expand|Select|Wrap|Line Numbers
  1. "[ID #]=[Forms]![ES Test Failure Enter New]![ID #]"
This is the filter that I have to preview the report, but do not see a location for it in the docmd.outputto section of my code. Do I need to open the report filtered first for it to only output the 1 record that they want? Or is there a little more to it? Do I need to filter the form first then run this operation? Do I need to change what form and what report(Based on a filter query) to run be for this code?

I hope what I'm asking for makes sense? Looking mostly for the right direction to follow or validation that I'm on the right track.
Jul 31 '19 #3
DJRhino1175
221 New Member
So what I ended up doing was:
1) Made a copy of that report, gave it a new name
2) Made a on open event
3) Updated my email code to use this report instead.
This worked like a charm. Although I'm sure there was a better way to do it, but it works.

Thanks Twinny for getting me to do some thinking instead of freaking....
Jul 31 '19 #4
twinnyfo
3,653 Recognized Expert Moderator Specialist
DJ,

I do what you are trying to do all the time. I use a global variable that the Report uses as a filter (you could also use that global variable as a criterion in your report's underlying query). Then, I simply export the report as a pdf, saving as a name particular to the "customer", generate an e-mail and attach that file. I even use this for massive mail-outs--I just loop through each recipient, generate the report, create e-mail, attach the report.
Aug 2 '19 #5

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

Similar topics

5
4539
by: Bob | last post by:
Hi, I am using Access 2000 to print out an address book. I have designed the report based on a database whose first record is not blank. In the design there is a one line report header, a onle line page header, three lines of detail (name address etc)and a footer. On previewing or printing the report it inserts a blank three line detail...
7
8368
by: Nothing | last post by:
I have a report based on a query that is based agaisnt two tables. The report pulls information for 1 customer. The tables may hold multipul customers. I want to email just the ONE report. All the options that I have found to email a report email multipul pages of the report, i.e. it sends all the information it can get fomr the query...
6
2238
by: John | last post by:
Hi, I have simple database based on 3 tables. Relationship is 'one to many' between table 1 and 2, also between 2 and 3 table'one to many'. I have made form where I enter data in all 3 tables. Form has 2 subform based on relationships. I want to make report to print data which is shown on form. I want to print only data from form, not...
3
2716
by: eddiec | last post by:
hi everyone, I have a report in an adp that uses aggregate functions in its record source and I am trying to figure out how to filter the records displayed in the report: DoCmd.OpenReport with a SQL string for the where condition does not work. The error returned is: The column prefix dbo.mytable does not match with a table name or alias...
0
1440
by: Crystal Report - LoadSaveReportException | last post by:
I have a web system which will display a crystal report for clients. It is written in Visual Studio 2003, VB.Net and Crystal Report which comes with VS2003, running on Windows 2000. It works very well. Now we moved it to Windows XP and I cannot run the report again at design time. There is no change to my code. I got the following error: The...
1
2007
by: gregoryenelson | last post by:
Hi all. I have created a Report with a graph also on it. The users, working through a form only (not the DB window) will want to view that Report run numbers of times against different criteria, probably simultaneously, and probably save it or print it --- so I cannot use the same report but must (I believe create copies of the original) I...
3
2471
by: ye2127 | last post by:
Hi, I have a report called 'schools' This report lists the percentage of schools performing a certain action In the 'schools' report I have a subreport which lists information on the percentage of classes performing a certain action. Thus the 'schools' report contains an output value of the percentage of...
46
3484
by: pixie | last post by:
Hi. I have an Access DB that is for contracts. I have used the code found on Tony's site for emailing a report per person containing only their information using GroupWise. It works great but I have a problem. Right now, the code before the GroupWise code, generates reports based on time criteria. If the query has no records for a person then...
2
2782
by: harley.mcnerthney | last post by:
I have an Access 2007 problem and I would just like to know if there is some sort of solution out there. The problem is, when I build a report that will 99% of the time be one page or less maybe even a half page. I end up with a giant space in the middle of my report. I want to fill that space with empty records but the records must only...
0
854
by: chrisdb | last post by:
I have done a seaarch on the form and found a few complex ways to password protect reports by converting snp's to pdfs etc. I'm using Access 2003 and the Do.Cmd SendReport function, which makes it very easy to run a bunch of reports and automatically email them out. Is there any simple way, perhaps if I upgrade to a newer version of Access, to...
0
7527
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7459
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7485
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7819
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5377
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5097
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3505
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1953
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1064
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.