Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Attaching an Access report for gmail

Status
Not open for further replies.

mdProgrammer

Programmer
Oct 2, 2004
71
US
I have code, found on the Internet, which can send an email to gmail (via an internal relay). How do I add an attachment of a report in the database? I can't use Outlook (I have code for this that has worked for years, but we're no longer using Outlook) due to switching to web-based email, and much of the report attachment code I've found uses MS Outlook.

Code:
Dim sMailServer
Dim sMailFromAddress
Dim sMailToAddress
Dim sMailAttachment As Attachment
Dim sSubject
Dim sBody
Dim sToAddress

sMailServer = SMTPServer
sMailFromAddress = fromEmail
sMailToAddress = ToEmail
Dim ObjMessage
Set ObjMessage = CreateObject("CDO.Message")
sToAddress = sMailToAddress
sSubject = "Subject"
sBody = "MailBody"

ObjMessage.Subject = sSubject
ObjMessage.FROM = sMailFromAddress
ObjMessage.To = sToAddress
'ObjMessage.cc = sCCAddress
ObjMessage.TextBody = sBody

[COLOR=#4E9A06]' Would like to attach a report from Access[/color][COLOR=#EF2929]ObjMessage.addattachment "file://c:\TestImage.jpg"[/color]

ObjMessage.configuration.Fields.Item("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendusing")[/URL] = 2
ObjMessage.configuration.Fields.Item("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserver")[/URL] = sMailServer
ObjMessage.configuration.Fields.Item("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserverport")[/URL] = 25
ObjMessage.configuration.Fields.Update
ObjMessage.Send

I also had a 2nd question similar to this issue (of outlook). Is it possible to change what email program is used when clicking on an email field? (i.e., when I click on an email in a table, it'll open up MS Outlook. This will no longer be the case).
 
Based on what I've seen on other forums try the path as it is on windows...

ObjMessage.addattachment "c:\TestImage.jpg"

As to your second question, what do you mean? Do you mean you have Mailto: hyperlinks you are clicking on? In that case change the default mail program for Windows. I haven't had to do this in forever, ask google where it is for your version of windows. If you have Embedded files, and want to reopen such as Outlooks proprietary .msg format, you are going to have to use outlook or use outlook to open each e-mal save to say an HTML file and load that back into the database so you can open with your HTML viewer of choice.
 
Unfortunately, where I work, they aren't going to be using Outlook anymore (or exchange server for that matter). What I was trying to get at with the first question was something like I did above (adding the test file does work), but instead of a test file, the report object in MS Access, like this -
somereport.jpg

(one of my applications has a function that sends the report as an email attachment when a form is completed. This works in Outlook just fine, as it opens the outlook window with the attachment shown). I was wondering what sort of code needs to be added to "ObjMessage.addattachment ". I even tried something like -
dim attach as Attachment
set attach.fileName = "..."
but it's read-only.
 
So you are saying the above code works, you just want to e-mail the report...

So export the report to pdf (below link) and then attach it...


Another thought, have you tried docmd.sendobject? I think it is Outlooks security model that makes this unfavorable... if you are not using Outlook, one line of code... I've never tried to use it so send a PDF so I don't know if they made that work with it or not. I remember getting snapshots (report snapshots, best there was before pdf support) to work was tricky... had to specify the item in the list exactly as it appeared to get it to work, but it did.
 
I found a work-around code to just save the PDF and then send that.

'Behind a comand button save the report as PDF file
DoCmd.OutputTo acOutputReport, "Report1", acFormatPDF, "reportname.pdf", False

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top