473,508 Members | 2,227 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to send email with a report as an attachment

82 New Member
I have a report. I have a button. What i want is: when user clicks the button, the report gets sent to some recipient. I searched all over the net, including this forum, and this site
http://www.granite.ab.ca/access/emai...ttachments.htm,
but i still have no idea how to do this and whether it can be done at all!..
I saw that everyone recommends to turn the report into a pdf file. But the command SendObject can't send a pdf file, can it? So even if i would create a pdf, how would i then send it?

P.S: Even creating pdf doesn't work, I'm running this line:
DoCmd.OutputTo acOutputReport, "rptEventProtocole", acFormatPDF, , False(or True, doesn't change anything)
access prompts me for an output format, and PDF is not one of the options in the list.
May 6 '10 #1
28 6633
Jim Doherty
897 Recognized Expert Contributor
@TravelingCat
Hi

If you are using Access 2000 then my advice to you is to have a look at Stephen Lebans site at this page

http://www.lebans.com/reporttopdf.htm

Stephen has officially retired from Access but his wonderful efforts over the years to the Access community has helped many people. I for one know his contribution to output a report to PDF was a great contribution relying on a couple of DLLs he created that are dumped in the same folder as your mdb file. Don't expect any support on this. given his retirement, but if it is to tide you over until you upgrade then it is an easy method to employ.

Get your head around creating the PDFs from report based objects first, then the email thing can be dealt with when you understand how the PDF creation aspect works
May 6 '10 #2
TravelingCat
82 New Member
Thanks, but i already downloaded the mdb from this site, but there's so much code which i don't even understand... i wonder if i really need all this. And i'm using access 2003. I don't understand, why for doing the same thing - creating a pdf - one site has a whole mdb, and the other one line of code?..
DoCmd.OutputTo acOutputReport, "Name of Report in MDB", acFormatPDF, "Path/Name of report on hard drive", False
And why doesn't this line work for me?
And i would still like to know whether sending pdf via access is possible
I'm pretty frustrated by now, will appreciate any help..
May 6 '10 #3
Jim Doherty
897 Recognized Expert Contributor
@TravelingCat
Where did you get your reference to acFormatPDF? I did say Access 2000 when I referred to creating a PDF I summized this when you said PDF format was not an available option to you, in your output formats.

Both Access 2000 and Access 2003 do not send in these formats natively only Access 2007 does that. The workaround in the earlier versions of Access was to either buy a piece of third party software to do the job or pick up on Stephens free offering which I already said works and does exactly what it says on the tin...so to speak.

Stephen Lebans method converts an access report saved to disk as a snapshot file and converts it to PDF as an external file created on the fly as part of that process. It is this path of the newly created PDF file that you must pick up on and attach to any email message .

Like I said before I am afraid to say it is chicken and egg. If you want to achieve your aim the steps are necessary to first know how to implement Stephens method.........the grabbing of the external file to attach to an email message is the easy bit comparatively and well documented, with plenty of references of how to do that on here using office automation.

I am not saying for one minute that understanding this process is an easy task but it is necessary in order to achieve your ends I am afraid, as frustrating as that may be :)
May 6 '10 #4
patjones
931 Recognized Expert Contributor
Hi TravelingCat,

If I may just pick up on something in your first post...you mentioned that everyone recommends converting the report to PDF format. However, for your purposes is it necessary to have it in PDF format or are any of the other formats presented in the list alright? If other formats are acceptable to you then this process could become easier.

Pat
May 7 '10 #5
DataAnalyzer
15 New Member
I use Total Access Emailer. It'll let you send emails to everyone in your list, reference fields from your table and attach the pages of the report for each contact. It filters the report based on a field in your email list. The 2007 version support the reports as PDFs.

Runs as an add-in wizard so no programming is required. There's a VBA interface if you need that.

Good luck
May 9 '10 #6
TravelingCat
82 New Member
Jim, the reference is from this site, http://www.granite.ab.ca/access/emai...ttachments.htm. I did change the "Snapshot Format" to acFormatPDF, just because there was such option in the vba, but it didn't work. Thank you for detailed answer, i will look deeper in the way you suggested.
Zepphead80, other formats are not acceptable unfortunately, there's not much to choose from, and rtf is just horrible, it distorts the whole report. But pdf document can't be modified, and in addition to be able to send a report by mail, my user wants to be able to design the report before printing it - meaning change font, size, etc., and then i also should save it back to mdb including the changes he made.. i have no idea so far as to how it will be implemented.. I will have to ask for help from my colleague, otherwise.... it won't be pretty:)
DataAnalyzer, i understand that this program is not free, so that is not a option for me.
Anyway, thank you for all your replies, i'll continue working on it
May 13 '10 #7
TravelingCat
82 New Member
Me again.. Jim, since you recommended Stephens program so highly, i have 2 questions to you:)
I've put his code into my program, but how do i add a condition to the report that is being saved? When i had a "view report" button, it had this condition:
DoCmd.OpenReport "rptEventProtocole", acViewDesign, , "eventNum = " & evNum, it presented the event that was currently on the screen.
And number two, the code doesn't support hebrew language.. it comes out with question marks. Is there a way to fix it?
Oh, and of course, now that i have the pdf file, how do i send it via outlook?
Thanks for your help
May 13 '10 #8
Jim Doherty
897 Recognized Expert Contributor
@TravelingCat
I had no idea from your post that internationalisation would be eluded to I am afraid. I cannot answer every eventually resolving issues related to Hebrew time, date, and numerical formats with Stephens offering it was always a developmental idea, free, and for the most part works.

It may well be that your only option is to buy a third party software or upgrade to a later version of Access I am afraid.

In relation to your report criteria. It is generally better if you can pass some criteria to your report at runtime from some other object in your database ie: a form based control ie a textbox that can pass the value to the report as it opens. I see that you are opening your report in design mode (but why I do not know) You can open the report acViewNormal and still pass criteria to the report

The following block of code will open a report based on some string criteria (note: not numeric datatype) that is passed from a Form control textbox. The report is opened in design mode and the criteria is passed to the filter property of the report. You are then prompted to ave the changes (amend to suit)

Expand|Select|Wrap|Line Numbers
  1. Dim stDocName As String
  2.     Dim mycriteria As String
  3.     stDocName = "rptEventProtocole"
  4.     mycriteria = "[LN]='" & Me!txt1 & "'"
  5.     MsgBox "The criteria for your report is " & mycriteria
  6.     'DoCmd.OpenReport stDocName, acPreview, , mycriteria
  7.     DoCmd.OpenReport stDocName, acDesign, , mycriteria
  8.     Reports!rptEventProtocole.Filter = mycriteria
  9.     DoCmd.Close acReport, "rptEventProtocole", acSavePrompt
The next block of code will open that same report based on the same form control but this time just in preview mode passing the criteria straight to the report as part of the where clause argument to the Docmd.openReport command


Expand|Select|Wrap|Line Numbers
  1. Dim stDocName As String
  2.     Dim mycriteria As String
  3.     stDocName = "rptEventProtocole"
  4.     mycriteria = "[LN]='" & Me!txt1 & "'"
  5.     MsgBox "The criteria for your report is " & mycriteria
  6.     DoCmd.OpenReport stDocName, acPreview, , mycriteria

At lastly, if the PDF hebrew conversion issue persists to be a problem (and I am not in a position to debug that) is there much point in me giving you help on attaching an external PDF filename to an email message and sending via an outlook email message?
May 13 '10 #9
TravelingCat
82 New Member
Hi, thanks for your quick reply.
Well i guess not, no point... (in giving me advice about email).
Anyway thanks a lot for your input on this subject, i will try to figure out some other way.
May 13 '10 #10
TravelingCat
82 New Member
I found how to change the language:) So if it isn't too much trouble, i would really like to hear how to send the file
May 13 '10 #11
TravelingCat
82 New Member
And also, about the thing with criterias. When i used to just open the report for preview there was no problem, it opens like i need it to. But i was wondering where do i put this criteria in Stephen's code.
Inside 'Public Function ConvertReportToPDF' there is a 'DoCmd.OutputTo ....', but it has no 'where' clause, so i don't know how to condition it
May 13 '10 #12
patjones
931 Recognized Expert Contributor
Hi,

The following subroutine, which I use in one of my Access projects, takes one or more email addresses (strSendTo), a subject (strSubject), a message for the body of the email (strBody) and a file path (strAttachFile) as arguments and sends the email:

Expand|Select|Wrap|Line Numbers
  1. Public Sub SendEmail(strSendTo As String, strSubject As String, strBody As String, Optional strAttachFile As String)
  2.  
  3. Dim olApp As New Outlook.Application, olMail As Outlook.MailItem
  4. Set olMail = olApp.CreateItem(olMailItem)
  5.  
  6. With olMail
  7.  
  8.     .To = strSendTo
  9.     .Subject = strSubject
  10.     .ReadReceiptRequested = False
  11.     .Body = strBody
  12.  
  13.     'Attachment is optional...
  14.     If Not IsNull(strAttachFile) Then .Attachments.Add strAttachFile
  15.  
  16.     .Send
  17.  
  18. End With
  19.  
  20. Set olApp = Nothing
  21. Set olMail = Nothing
  22.  
  23. End Sub

Bear in mind that it sends a file. So you would previously have had to output the report to some location, and then specify the path to that location in strAttachFile above. I'm not certain whether you can send the report directly without outputting it first.

Pat
May 13 '10 #13
TravelingCat
82 New Member
zepphead, the following line:
Dim olApp As New Outlook.Application
gives me an error: User-defined type not defined
May 13 '10 #14
patjones
931 Recognized Expert Contributor
Yes, I forgot to tell you to set the reference to the Outlook library. Go Tools > References... and in the long list of available references scroll down and check off "Microsoft Outlook 12.0 Object Library". It should compile after that.

Pat
May 13 '10 #15
Jim Doherty
897 Recognized Expert Contributor
@TravelingCat
OK I see Zepphead has dealt with the email aspect :) so I have no need to enlarge on that.

In relation to opening the report:- You do not need to alter Stephens code for that purpose you simply pass the full name of the report and the function opens the report and outputs it as expected.

In relation to passing a string criteria for the where clause you can do this in different ways. The report itself can look for something external to itself to set its criteria/filter property when the report itself opens.

One way of doing this is to simply create a Global variable of the String type. A global variable is available throughout your application. In other words the value contained in it is not tied to anything in particular. You place this global variable in a module and set the value of this global variable from your calling code.

Create a new module and paste the following into it immediately underneath the 'Option Compare Database' line. Save the module with a meaningful name for instance mod_Globals

Expand|Select|Wrap|Line Numbers
  1. Global MY_CRITERIA As String
  2.  
  3. Public Function GetMyCriteria()
  4. GetMyCriteria = MY_CRITERIA
  5. End Function

Now go to your report in design mode and in the 'On Open' event of the report
paste into it the following code so it looks like this

Expand|Select|Wrap|Line Numbers
  1. Private Sub Report_Open(Cancel As Integer)
  2. On Error Resume Next
  3. Me.Filter = GetMyCriteria()
  4. Me.FilterOn = True
  5. End Sub

Now imagine we have a command button on a form (or something similar) and we want to open the report passing some filtration criteria to the report as it opens. We achieve this by first setting the value of the global variable (which is automatically picked up by the report which in turn applies this criteria to itself) Get the idea?

Below is an example of opening that report from a command button mounted on a form as mentioned above. The syntax required to do so is as follows:.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2. On Error GoTo Err_Command1_Click
  3.     Dim stDocName As String
  4.     Dim mycriteria As String
  5.     stDocName = "rptEventProtocole"
  6.     MY_CRITERIA = "[LN]='" & Me!txt1 & "'"
  7.     DoCmd.OpenReport stDocName, acPreview
  8. Exit_Command1_Click:
  9.     Exit Sub
  10.  
  11. Err_Command1_Click:
  12.     MsgBox Err.Description
  13.     Resume Exit_Command1_Click
  14.  
  15. End Sub
Notice in the code block above, there is NO criteria argument on the DoCmd.Openreport command line. In this instance there is no need to express this because the report is synchronising any underlying dataset by reference to its filter property and the value contained in the global variable when the report itself opens.

This is just one of many different techniques that exist it is by no means the only one.

Hope this helps!
May 13 '10 #16
TravelingCat
82 New Member
Hi, i got back from the weekend.
Thanks a lot for your time and help, and sorry for this neverending post, but..
zepphead, i have "Microsoft Outlook 11.0 Object Library", and when i try to check it off it says "can't remove control or reference; in use"... any ideas?
Jim, thanks a lot for the help, i managed to make it open what i need
May 16 '10 #17
patjones
931 Recognized Expert Contributor
Hi,

I think I worded my post the wrong way...I apologize. I mean that it should be checked. You want to have that reference turned on.

Pat
May 17 '10 #18
TravelingCat
82 New Member
Well then why doesn't it compile, do you know?
May 17 '10 #19
patjones
931 Recognized Expert Contributor
Can you post the code, the error your getting and note the line the compiler is complaining about? Thanks.

Pat
May 17 '10 #20
TravelingCat
82 New Member
Hi, here's the code (in bold is the line where compiler gets stuck, it's right after the first Dim)
Expand|Select|Wrap|Line Numbers
  1. Private Sub btnSendProtocole_Click()
  2. Dim olApp As New Outlook.Application
  3. Dim olMail As Outlook.MailItem
  4. Set olMail = olApp.CreateItem(olMailItem)
  5.  
Here's the message:
"Compile error: User-defined type not defined"
May 20 '10 #21
patjones
931 Recognized Expert Contributor
Right, and this is because the reference to the Outlook library is not set. If that reference is checked, then this code should compile.

Pat
May 20 '10 #22
TravelingCat
82 New Member
Wow zepphead i'm so sorry... i didn't have it checked, the whole time i was looking at this Microsoft Access Object Library, i was reading Access but thinking Outlook.. i should've doublechecked.
Thank you very much for your time spent on this:)
May 20 '10 #23
patjones
931 Recognized Expert Contributor
It's no problem at all. That's what the forum is for. And now for the real purpose of your post...does the report get sent along with the email?

Pat
May 20 '10 #24
TravelingCat
82 New Member
I have to leave now, I will check it on Sunday and will let you know about my progress
May 20 '10 #25
TravelingCat
82 New Member
After a really quick check i see that he can't find the file, i'm passing a path, which is correct. I'll look into it later
May 20 '10 #26
TravelingCat
82 New Member
Hi again, i forgot to pass the file extension.. .so now it works perfectly and sends the file, thank you!
You said earlier that you're not certain whether i can send the report directly without outputting it first, so just out of curiosity, how do you use this code in your program? Do you first save the file and then send it?
May 23 '10 #27
patjones
931 Recognized Expert Contributor
The report that I send goes out to several supervisors within my division on a weekly basis, however I like to keep a copy in a designated spot on my local drive for reference later. So I output it to that location then email it as an attachment.

I could very well just output the report to a spot on the network drive that everyone has access to, and point them to where it is - but I think people like to be able to just click on it when it arrives as an email attachment. Not to mention that Outlook has the ability to preview PDF's right in the message window.

Pat
May 23 '10 #28
TravelingCat
82 New Member
Got it
Well, thank you very much for all your help, i definitely achieved something thanks to you and Jim:) These forums are great
May 24 '10 #29

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

Similar topics

1
2569
by: Christian Otteneuer | last post by:
Hello NG, How can I send an email with an attachment from a python script? My code so far: mailhost = container.mailHost mMsg = 'MessageText' mTo = 'you@you.com' mFrom = 'me@me.com' mSubj...
0
1612
by: Andrew Chan | last post by:
Dear All, I'm new in VS C++.I would like to write a c++ program that can be send email with attachment,and all the input will be call from a file ( such as To Email address, attachment path). ...
2
2547
by: Fred | last post by:
Is there a good code sample, in C#, showing how to send eamil with attachment, from a Windows Form like 'Send To' in Word, that will pickup Contacts in Outlook/Exchange 2000. I have searched...
2
11031
by: m_evergreen | last post by:
Errors: An unhandled exception of type 'System.Web.HttpException' occurred in system.web.dll Additional information: Could not access 'CDO.Message' object. innerexception is "Exception has...
2
2237
by: kamlai | last post by:
I'm using PHP 5 with apache in linux. I'm now have a $content which stores the content of the email in HTML format. I would like to send this $content as the attachment of the email. How to deal...
2
1174
by: f_salazar | last post by:
Hi All, Im using VS 2003, VB.Net and embbed Crystal Report 9. How can I send by mail a report from Crystal; I try many samples i find on the web, but nothing works. any help will be...
1
9257
by: shil | last post by:
Hi, I'm using FW 2.0 to send an email with an attachment using System.Net.Mail class. If I try to attach a file from my file system, I could successfully send the eamil. But I need to generate a...
1
3116
by: monyrajesh | last post by:
<%@LANGUAGE="VBSCRIPT"%> <% nam=request.Form("name") mail=request.Form("email") phoneres=request.Form("res") phonembl=request.Form("mobile") adrs=request.Form("address")...
4
2157
by: PleaseHelpMe | last post by:
Any1 can tell me how to go about sending email with attachment in vb programming code. I know SMTP is one option, but I can't seem to get it working. Any other suggestion?? Thanks in advance
0
3430
by: ram1927 | last post by:
Here is my platform: .net framewrok 1.1 Windows Xp Propfessional MS Office 2007. Visual Studio 2003. Window based application. I did below mentioned steps: 1. Right click on C#...
0
7231
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,...
0
7132
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...
0
7401
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...
1
7063
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
5640
agi2029
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,...
0
3211
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...
0
3196
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
432
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.