Sending Individual Reports To Individual Emails (1 Viewer)

MarkyC

New member
Local time
Today, 05:58
Joined
Oct 14, 2010
Messages
8
I have no idea how best to explain this, which makes it even harder to find a search string to use to look on the internet, so I'm hoping you guys can help me.

I have a report which groups information by person. So each person has some detailed information on a page (including the person's email field) before there's a page break, and then next page shows the next person's details. Currently, the process is to email this whole report to a number of users. However, they're only interested in their own individual page, and don't really need the other information. Is it possible to somehow automate so that each user is emailed his/her individual page of the report?

Or would this have to be a manual process (i.e. using a query where you select the person's name, which then only runs the report for that user, and emailing manually)?

I'm not an Access expert, I just generally use it for data manipulation with queries, so Access reporting is all new to me. Many thanks in advance, if you can assist.
 

MarkyC

New member
Local time
Today, 05:58
Joined
Oct 14, 2010
Messages
8
Thanks for the speedy reply pbaldy, I'll have a look through that and see if I can make sense of it :)
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 21:58
Joined
Aug 30, 2003
Messages
36,126
No problem, and post back if you get stuck. There's a lot of info there. Welcome to the site by the way!
 

MarkyC

New member
Local time
Today, 05:58
Joined
Oct 14, 2010
Messages
8
Many thanks for both the help and the kind welcome. All sorted now.
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 21:58
Joined
Aug 30, 2003
Messages
36,126
Excellent, glad it helped you.
 

Explorer

Registered User.
Local time
Yesterday, 21:58
Joined
Oct 16, 2010
Messages
12
Many thanks for both the help and the kind welcome. All sorted now.
Hey MarkyC,
That is exactly what I am trying to do with Access 2007 reports. Would you please let me know what exactly you did to sort this problem out. I tried to follow the steps but somehow it is not working.
It will be a great favor. I just want to know what individual steps you took...
Thanks so much in advance.
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 21:58
Joined
Aug 30, 2003
Messages
36,126
If you post your code and what "not working" means, we can probably sort it out for you.
 

Explorer

Registered User.
Local time
Yesterday, 21:58
Joined
Oct 16, 2010
Messages
12
Thank you Paul,
I tried to follow the link that you have mentioned on top but couldn't figure out. Then I googled and found this article shown below. I am not sure if the article shown below achieves the purpose that I am looking for but I tried to run it. It gives me an error. I would appreciate the detailed steps to sort out this email automation problem. Here it is:


Article ID: 318881 - Last Review: October 11, 2004 - Revision: 3.4
How to use a recordset to send Outlook e-mail to multiple recipients in
Microsoft Access


This article describes how to use Automation to send a Microsoft Outlook e-mail message to multiple recipients whose addresses are listed in a Microsoft Access
table. This article also uses Access form controls to add the message body, to fill in
the Cc field, and to fill in the Subject field. Additionally, this article describes a
programmatic method that you can use to include e-mail attachments and to
resolve e-mail addresses against the Outlook Address Book.


To create an Outlook session from Access and to use a recordset to send e-mail
messages to multiple recipients, follow these steps:

1. Create a text file that you can use as an attachment. Save the text file as
"TestAttachment.txt" in the root of drive C. For example, you can save the
text file as C:\TestAttachment.txt.
2. Create a new database that is named Db1.mdb.
3. Create a new table with the following information in Db1.mdb:

Table: tblMailingList
‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
Field Name: EmailAddress
Data Type: text


4. Type several valid e-mail addresses in the EmailAddress field.

5. Create a form with the following information:


Form: frmMail

‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐

RecordSource: tblMailingList

Text box
‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
Name: CCAddress
ControlSource: Unbound
Label Caption: CC Address


Text box
‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
Name: Subject
ControlSource: Unbound
Label Caption: Subject


Text box
‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐
Name: MainText
ControlSource: Unbound
Label Caption: Message Body


6. Open the form in Form view, and then type sample data in the appropriate
boxes. Press ENTER after each entry, and then leave the form open when
you are finished.


7. Create a new module. Add the following code sample to the new module.

Option Compare Database
Option Explicit
Sub SendMessages(Optional AttachmentPath)
Dim MyDB As Database
Dim MyRS As Recordset
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim TheAddress As String
Set MyDB = CurrentDb
Set MyRS = MyDB.OpenRecordset("tblMailingList")
MyRS.MoveFirst
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
Do Until MyRS.EOF
' Create the e-


mail message.



Set objOutlookMsg = objOutlook.CreateItem(olMailItem)


TheAddress = MyRS![EmailAddress]

With objOutlookMsg
' Add the To recipients to the e-

mail message.



Set objOutlookRecip = .Recipients.Add(TheAddress)


objOutlookRecip.Type = olTo

' Add the Cc recipients to the e-

mail message.



If (IsNull(Forms!frmMail!CCAddress)) Then


Else

Set objOutlookRecip = .Recipients.Add(Forms!frmMail!
CCAddress)
objOutlookRecip.Type = olCC
End If
' Set the Subject, the Body, and the Importance of the email message.
.Subject = Forms!frmMail!Subject
.Body = Forms!frmMail!MainText
.Importance = olImportanceHigh 'High importance
'Add the attachment to the e-

mail message.



If Not IsMissing(AttachmentPath) Then


Set objOutlookAttach = .Attachments.Add(AttachmentPath)

End If
' Resolve the name of each Recipient.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
If Not objOutlookRecip.Resolve Then
objOutlookMsg.Display
End If
Next
.Send
End With





8. In the Visual Basic Editor, click References on the Tools menu.

9. In the Available References list, click Microsoft Outlook 8.0 Object Library, and then click OK.

Note You have to select the correct Microsoft Outlook Object Library. The
Microsoft Outlook Object Library that you select depends on the version of


Outlook that is installed on your computer. For example, if you have Office

Outlook 2003 installed on your computer, click

Microsoft Outlook 11.0 Object Library.



10. Press CTRL+G to open the Debug window.



11. To send the e-mail message with an attachment, type the following command in the Debug window:


SendMessages "C:\TestAttachment.txt" Press ENTER.

Alternatively, to send the e-mail message without an attachment, omit the argument when calling the procedure. Type the following command in the Debug window:


SendMessages


Press ENTER.



Microsoft Support ©2010 Microsoft

 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 21:58
Joined
Aug 30, 2003
Messages
36,126
That code will not accomplish your stated goal, at least not without significant changes.
 

Explorer

Registered User.
Local time
Yesterday, 21:58
Joined
Oct 16, 2010
Messages
12
Paul,

That is exactly what I suspected. My automation problem is exactly what MarkyC had mentioned originally. Just want to send individual reports to respective individual recipients as an attachment with a standard message going with each email. Don't know how to write the code but if MarkyC has come up with a code for his database and shares it with me, I can probably modify it according to my database.
At this point it looks like I have to read thousands of pages from an Access 2007 book before I will be able to tackle this problem. Even then I am not sure of tackling it. Oh well...
 

lcbadelles

New member
Local time
Today, 08:58
Joined
Oct 20, 2010
Messages
3
Hi Everyone,

I hope you can help me on this same problem. As per the code above, i want to know how does the sending of message works with attachments based from a reference path field in the tblMailingList? For example, instead of running the code by typing Send Message "C:\textfile.txt", i want to run it automatically with the field name in my recordset tblMailingList. example Send Message (Name of the field from the recordset). Please help. Thank you.

L
 

Explorer

Registered User.
Local time
Yesterday, 21:58
Joined
Oct 16, 2010
Messages
12
Hey L,

Thanks for keeping this thread alive. I am still waiting to solve my problem mentioned above. Hopefully a messiah will come one day and will explain how to accomplish this automation. I know its very much possible. MarkyC seems to have sorted it out but he is not answering anymore.
Meanwhile I have started reading some books and If I figured this out I will certainly share it with the rest of the community.
If you happen to solve this problem somehow, please don't forget to share it on this thread. Please...please...please....You don't know how many hours it will save me.
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 21:58
Joined
Aug 30, 2003
Messages
36,126
Has any of your extensive research involved reading through the link (and the related links) that I posted earlier? It seemed to be enough for MarkyC to solve the problem, so it should at least be enough to get both of you started. If you run into problems, post them and we'll sort it out.
 

Explorer

Registered User.
Local time
Yesterday, 21:58
Joined
Oct 16, 2010
Messages
12
Hey Paul,

I am sorry if I have offended you. Remember I mentioned in my first post I am a beginner. I tried to read the links posted by you and my level of understanding is not up to the level of codes so far. Therefore I could not figure out your links.

So let me ask this question-Is this automation problem solvable by writing codes only? Or we can also do it by following the Forms-Queries-Reports combination too?
So far I have been able to generate the paper reports by using only queries and report combination without writing a single line of code. Very basic stuff you know.
Let me know and thanks for replying...
 

lcbadelles

New member
Local time
Today, 08:58
Joined
Oct 20, 2010
Messages
3
Hi Paul,

I am not sure if the link you provided answers my queries although it is very interesting and a good point of reference for future use. But it still doesn't answer my question. I just want to know how to automate the attachments by not typing the path (e.g. see below...

he e-mail message with an attachment, type the following command in the Debug window:


SendMessages "C:\TestAttachment.txt" Press ENTER.

I would really appreciate if you can help me on this. Please see the post from Explorer. Sorry if i must have missed something. Thank you.

L
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 21:58
Joined
Aug 30, 2003
Messages
36,126
Explorer: Not offended, but I don't see any effort to work through the provided code. I think this solution will require code. You could probably do a single report for a specified person without, but not to loop through and send each person a personalized report.

lcbadelles: In a link off the link I posted is this, which will let you specify an attachment:

http://support.microsoft.com/?kbid=161088

and that could come from a form or recordset:

SendMessage True, Forms!FormName.Whatever

or

SendMessage True, rs!FieldName
 

lcbadelles

New member
Local time
Today, 08:58
Joined
Oct 20, 2010
Messages
3
Hi,

THanks for the reply but i received this error. Let me know what i did wrong. THank you.


Run-Time error '483':

Object doesn't support this property or method.

Set objOutlookAttach = .Attachments.Add(AttachmentPath)

after writing the code as you have instructed...

SendMessage True, Forms!frmMail.Attachment_path
 

MarkyC

New member
Local time
Today, 05:58
Joined
Oct 14, 2010
Messages
8
Hi, and sorry I hadn't seen the posts in here until now. I got your PM Explorer, but thought I'd reply in here in case anyone else was interested. My technique for resolving my problem was far from genius, as I'm not an expert in Visual Basic myself. So to all the aces on here it might seem long-winded and stupid :D

Anyway, here's how I do it.

First of all, I have a table set up called DISTRIBUTE, which is populated with only two fields, name and email, from a query that runs at a certain point. This query checks a few other tables and makes sure (in my case) that only emails are sent out to people who appear on the report in the first place. Anyway, this is populated from a Make Table query, which obviously deletes and recreates the table each time, and then dumps the names and emails in.

Next I have a form which contains four fields.

Email Address
Subject
Message Body
Attachment

The email address field is a combo box which reads from the DISTRIBUTE table. Therefore, when the form loads (in single view) it shows the first record in the table.



This form has an on timer event procedure set up to run every 3 seconds which then runs this code (which I found on a search after finding the right track from the links pbaldy posted):

If DCount("*", "DISTRIB_CHECK") > 0 Then
DoCmd.OutputTo acOutputReport, "INVOICE_RPRT_AUTO", acFormatPDF, "C:\ZDB\INVOICE.PDF"
Dim mess_body As String
Dim appOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)

Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)
With MailOutLook
.BodyFormat = olFormatRichText
.To = Me.Email_Address
.Subject = Me.Mess_Subject
.HTMLBody = Me.mess_text
If Left(Me.Mail_Attachment_Path, 1) <> "<" Then
.Attachments.Add (Me.Mail_Attachment_Path)
End If
.Send

DoCmd.SetWarnings False
DoCmd.OpenQuery "DISTRIB_COMP_AUTO"
DoCmd.Close acForm, "INVOICE_MAIL_AUTO"
DoCmd.OpenForm "INVOICE_MAIL_AUTO"
DoCmd.OutputTo acOutputReport, "INVOICE_BLANK", acFormatPDF, "C:\ZDB\INVOICE.PDF"

End With
'MsgBox MailOutLook.Body
Exit Sub
email_error:
MsgBox "An error was encountered." & vbCrLf & "The error message is: " & Err.Description
Resume Error_out
Error_out:

Else
MsgBox "Distribution list is now empty. All outstanding invoices sent"
DoCmd.Close
DoCmd.OpenForm "INVOICE_MENU"
End If


So I first check that the table isn't empty (with a query DISTRIB_CHECK). If not, it will open the report which is looking at the form information currently on screen (i.e. the of first record in the table DISTRIBUTE). Then it emails to the person selected. Then it runs a query "DISTRIB_COMP_AUTO" which is a delete query, which deletes this current record from the table (thus not able to email to it again).

Then it closes the form and reopens to start over again, with the next record in the table. Hope that makes sense.

Like I said, it's not pretty at all because I'm not great with code, but it does the job, if in severely messy fashion.
 
Last edited:

MarkyC

New member
Local time
Today, 05:58
Joined
Oct 14, 2010
Messages
8
Also, important, you have to select the Outlook method in the references in Visual Basic otherwise mailing won't work at all.
 

Users who are viewing this thread

Top Bottom