i have multiple reports (Report1, 2 , 3 ... 8) auto generated and saved to a file C:\Reports. can someone assist with code on one Click to a button to send these to multiple recipients in tblEmployees with the EmployeeEmail Field containing email addresses of the recipients Report1 sent to MrXXX with email-mrxxx@gmail.com, Report2 sent to Mryyy with email-mryyy@yahoo.com. i am using ms access2013.
14 2718
thanx Seth but the code seems similar to what i have which is sending a single email to multiple recipients. what i am looking for is a way to send multiple emails to multiple recipients. each email sent to a specific recipient in the database attaching a report.
Is each report going to multiple people or just one person?
each report is going to a single person (regional manager). point to note these report contain regional information used by different regional managers in the table tblEmployees.
here is the code that i have which is perfectly sending the report to multiple recipients - Private Sub Command24_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 FileName As String
-
Dim FilePath As String
-
-
'Generate a Report
-
FileName = Me.Name & "_ID "
-
FilePath = "C:\Reports\" & FileName & ".pdf"
-
DoCmd.OutputTo acOutputReport, "rptBranches", acFormatPDF, FilePath
-
MsgBox "Report has been saved succesfully", vbOKOnly, "Save confirmed"
-
-
Set oOutlook = CreateObject("Outlook.Application")
-
Set oMail = oOutlook.CreateItem(0)
-
-
'Retrieve all E-Mail Addressess in Regional_Managers
-
Set MyDB = CurrentDb
-
Set rstEMail = MyDB.OpenRecordset("Select * From Regional_Managers", dbOpenSnapshot, dbOpenForwardOnly)
-
-
With rstEMail
-
Do While Not .EOF
-
'Build the Recipients String
-
strEMail = strEMail & ![EmailAddress] & ";"
-
.MoveNext
-
Loop
-
End With
-
'--------------------------------------------------
-
-
With oMail
-
.To = Left$(strEMail, Len(strEMail) - 1) 'Remove Trailing ;
-
.Body = "Test E-Mail to Multiple Recipients"
-
.Subject = "Yada, Yada, Yada"
-
.Attachments.Add FilePath
-
.Display
-
End With
-
-
Set oMail = Nothing
-
Set oOutlook = Nothing
-
-
rstEMail.Close
-
Set rstEMail = Nothing
-
Kill FilePath
-
-
End Sub
-
So then you will need to have a table that has the report name and the email address that it will go to and (optionally) the File name that you want used. You would then place your existing code inside a loop that goes through each record getting the report name and the email address from the table.
is there no other way to alter the current code i have
You can copy your existing code and paste it at the end for every report. You would have to hard code the email addresses then.
Seth is right, one way or another you'll need a way to map which Report goes to which Manager. By itself, Access can't pull that off. If you already have that relationship built somehow in your database, like a table, query or function, then it might be possible to reuse it. If that information isn't defined in any way, then it would need to be defined to do what you are requesting.
Hi Buddies. i hope you had a great weekend. I have created the query RMsReports with ReportNames and EmailAddresses from the tblEmployees table as you advised. Now its coding time i cant seem to figure out where exactly am i going to put the loop. may modify my code please.
Start the loop on line 12 and end the loop on line 49. You would then replace the static report name in line 16 with the value from the query and then obviously the To email address.
Seth please help i am stuck here. I am confused and lost completely. this is the actual code i am working on. - Private Sub SADM_Weekly_Performance_Click()
-
Dim db As DAO.Database
-
Dim rs As DAO.Recordset
-
Dim MyFileName As String
-
Dim temp As String
-
Dim mypath As String
-
-
Dim strEMail As String
-
Dim oOutlook As Object
-
Dim oMail As Object
-
Dim rstEMail As DAO.Recordset
-
Dim attach As String
-
Dim address As String
-
-
mypath = "C:\Users\EWM\Desktop\Auto\SADM Wkly Performance - "
-
-
Set db = CurrentDb()
-
Set rs = db.OpenRecordset("SELECT distinct [Region] FROM [SADM Performance Per Week Query]", dbOpenSnapshot)
-
-
'--------------------------------Generate Split and save the report pdf file---------------------------------------------------------------
-
Do While Not rs.EOF '
-
temp = rs("Region")
-
MyFileName = rs("Region")
-
-
Debug.Print "Generated Path for " & temp & " - " & mypath & MyFileName
-
-
DoCmd.OpenReport "sadm performance per week", acViewReport, , "[Region]='" & temp & "'"
-
DoCmd.OutputTo acOutputReport, "", acFormatPDF, mypath & MyFileName & Format(Date, "dd/mmmm/yy") & ".pdf"
-
DoCmd.Close acReport, "sadm performance per week"
-
DoEvents
-
-
rs.MoveNext
-
-
Loop
-
'--------------------------------------------------------------------------------------------------------------------------------
-
-
Set rstEMail = db.OpenRecordset("Select * From RMsReports", dbOpenSnapshot, dbOpenForwardOnly)
-
-
With rstEMail
-
Do While Not .EOF
-
-
Set oOutlook = CreateObject("Outlook.Application")
-
Set oMail = oOutlook.CreateItem(0)
-
-
'Build the Recipient String
-
address = ![EmailAddress] & ";"
-
-
'Build attachment String
-
attach = ![Path] & ".pdf"
-
-
With oMail
-
.To = address
-
.Body = "Please find attached weekly SADM Performance Report"
-
.Subject = MyFileName
-
.Attachments.Add = attach
-
.Display
-
End With
-
-
Set oMail = Nothing
-
Set oOutlook = Nothing
-
-
.MoveNext
-
Loop
-
End With
-
-
rs.Close
-
Set rs = Nothing
-
Set db = Nothing
-
-
End Sub
-
Mates i finally got it thanks to Seth's idea. Here is my final Code - Option Compare Database
-
-
Private Sub SADM_Weekly_Performance_Click()
-
Dim db As DAO.Database
-
Dim rs As DAO.Recordset
-
Dim MyFileName As String
-
Dim temp As String
-
Dim mypath As String
-
-
Dim strEMail As String
-
Dim oOutlook As Object
-
Dim oMail As Object
-
Dim rstEMail As DAO.Recordset
-
Dim attach As String
-
-
-
mypath = "C:\Auto\SADM Wkly Performance - "
-
-
Set db = CurrentDb()
-
Set rs = db.OpenRecordset("SELECT distinct [Region] FROM [SADM Performance Per Week Query]", dbOpenSnapshot)
-
-
'--------------------------------Generate Split and save the report pdfs to file---------------------------------------------------------------
-
Do While Not rs.EOF '
-
temp = rs("Region")
-
MyFileName = rs("Region")
-
-
Debug.Print "Generated Path for " & temp & " - " & mypath & MyFileName
-
-
DoCmd.OpenReport "sadm performance per week", acViewReport, , "[Region]='" & temp & "'"
-
DoCmd.OutputTo acOutputReport, "", acFormatPDF, mypath & MyFileName & Format(Date, "dd/mmmm/yy") & ".pdf"
-
DoCmd.Close acReport, "sadm performance per week"
-
DoEvents
-
-
rs.MoveNext
-
-
Loop
-
'--------------------------------------------------------------------------------------------------------------------------------
-
-
Set rstEMail = db.OpenRecordset("Select * From RMsReports", dbOpenSnapshot, dbOpenForwardOnly)
-
-
With rstEMail
-
Do While Not .EOF
-
-
Set oOutlook = CreateObject("Outlook.Application")
-
Set oMail = oOutlook.CreateItem(0)
-
-
'Build the Recipient String
-
strEMail = ![EmailAddress] & ";"
-
-
'Build attachment String
-
attach = ![Path] & ".pdf"
-
-
With oMail
-
.To = Left$(strEMail, Len(strEMail) - 1)
-
.Body = "Please find attached weekly SADM Performance Report"
-
.Subject = MyFileName & " SADM Weekly Performance Report"
-
.Attachments.Add attach
-
.Display
-
End With
-
-
Set oMail = Nothing
-
Set oOutlook = Nothing
-
-
.MoveNext
-
Loop
-
End With
-
-
rs.Close
-
Set rs = Nothing
-
Set db = Nothing
-
-
End Sub
-
Glad you got it to work. Good luck on the rest of your project!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: news.microsoft.com |
last post by:
HI,
ASPEmail to send to multiple recipients?
I tried to use comma and semicolon but all the time give this message
error:
Error: 6 - 501 Bad address syntax
nor :...
|
by: Mike Wiseley |
last post by:
I want to insert a procedure call to the report close event of 50 or so
reports in a database. As each report is opened and then closed by a user, I
want to log the date this occurrred. I am...
|
by: Mega1 |
last post by:
is this possable to send more than 1 report in one email
|
by: Rod |
last post by:
We've got an old VB6 application which has 9 Crystal Reports it can print.
These 9 reports are considered by our users to be in essence one "report",
in the sense that they are all related and they...
|
by: joelpollock |
last post by:
I'm having trouble continuously page numbering a large report in MS
Access. The report is made up of three separate Access reports which I
join together at the end.
In the past I have opened the...
|
by: mfuentes74 |
last post by:
I have about 7 reports in access I need to print on a weekly basis. I wanted to know if there is any way I can do this faster then printing individual reports.
|
by: harmony123 |
last post by:
I would like to display the multiple records in multiple textboxes
Following is my tables and data:
tblJan with these data:
col id
1
2
3
col January
10
|
by: franda |
last post by:
hi i'm currently sending multi email recipients in one go is it possible to send it individually? please help thank you.
<?php
require_once 'library/config.php';
?>
<?php
$qe =...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
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...
| |