-
Option Compare Database
-
Option Explicit
-
-
Private Sub E_mailExt_Click()
-
-
Dim strEMail As String
-
Dim oOutlook As Object
-
Dim oMail As Object
-
Dim strAddr As String
-
Dim MyDB As DAO.Database
-
Dim rstEMail As DAO.Recordset
-
Dim strReportName As String
-
-
Set oOutlook = CreateObject("Outlook.Application")
-
Set oMail = oOutlook.CreateItem(0)
-
-
strReportName = "ES Test Failure"
-
-
DoCmd.OutputTo acOutputReport, "ES Test Failure Report", _
-
acFormatPDF, "N:\Lab\ES_Test_Failure_Reports" & "\" & strReportName & _
-
"-" & Format(Date, "mm-dd-yy") & ".pdf", False, , , acExportQualityPrint
-
-
'Retrieve all E-Mail Addressess in tblEMailAddress
-
Set MyDB = CurrentDb
-
Set rstEMail = MyDB.OpenRecordset("Select * From EXTEMail", _
-
dbOpenSnapshot, dbOpenForwardOnly)
-
-
With rstEMail
-
Do While Not .EOF
-
'Build the Recipients String
-
strEMail = strEMail & ![email] & ";"
-
.MoveNext
-
Loop
-
End With
-
'--------------------------------------------------
-
-
With oMail
-
.To = Left$(strEMail, Len(strEMail) - 1) 'Remove Trailing ;
-
.Body = "Please review the attached report."
-
.Subject = Replace(Replace("ES Test Failure # |1: P/N: |2", "|1", Nz([ID #], "")), "|2", Nz([Part Number], ""))
-
.Attachments.Add "N:\Lab\ES_Test_Failure_Reports" _
-
& "\" & strReportName & "-" & Format(Date, "mm-dd-yy") & ".pdf"
-
-
.Display
-
-
End With
-
-
Set oMail = Nothing
-
Set oOutlook = Nothing
-
-
rstEMail.Close
-
Set rstEMail = Nothing
-
-
Dim aFile As String
-
aFile = "N:\Lab\ES_Test_Failure_Reports\ES Test Failure.pdf"
-
If Len(Dir$(aFile)) > 0 Then
-
Kill aFile
-
End If
-
-
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?
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!
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. - "[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.
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....
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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...
|
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...
| |
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |