Wrox Programmer Forums
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 25th, 2004, 11:22 AM
Authorized User
 
Join Date: Jun 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default Email reports

Hi All - I'm looking for some help with email automation. I need to send a selected report ( the report is selected from a list) via email. I know that I could do it using sendobject command but i'd like to send it using a reference to the outlook or other VIM object. Here's where I'm stuck - I can't seem to get the report objects source path so that I can attach the report via the attachments.add function. Does anyone have any ideas or even a web link that might point me in the right direction?



William
__________________
William
 
Old August 26th, 2004, 12:42 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 625
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jemacc
Default

I have used this from another source.

Create a new module in your database with this information.

Make sure to have a with all email address. When I find the link to the article I will send it.

Option Compare Database
Option Explicit
' You need to declare a reference to the Outlook library, and the filesystemobject.
' this is not as hard as it sounds.
'
' Look in the menu above, and click Tools, then select References
'
' Scroll down the list until you see
' Microsoft Scripting Runtime -- and put a check next to it (if one is not there already)
'
' Microsoft Outlook Object Library -- check that.
' There will be some version number there as well; it doesn't matter.
' This will work with Outlook98 and Outlook2000 and OutlookXP. It hasn't been tested on Outlook 2003 yet.


Public Function SendEMail()

Dim db As DAO.Database
Dim MailList As DAO.Recordset
Dim MyOutlook As Outlook.Application
Dim MyMail As Outlook.MailItem
Dim Subjectline As String
Dim BodyFile As String
Dim fso As FileSystemObject
Dim MyBody As TextStream
Dim MyBodyText As String

Set fso = New FileSystemObject

 ' First, we need to know the subject.
 ' We can't very well be sending around blank messages...

Subjectline$ = InputBox$("Please enter the subject line for this mailing.", _
                 "We Need A Subject Line!")

 ' If there's no subject, call it a day.

If Subjectline$ = "" Then
    MsgBox "No subject line, no message." & vbNewLine & vbNewLine & _
        "Quitting...", vbCritical, "E-Mail Merger"
    Exit Function
End If

 ' Now we need to put something in our letter...

BodyFile$ = InputBox$("Please enter the filename of the body of the message.", _
             "We Need A Body!")

 ' If there's nothing to say, call it a day.

If BodyFile$ = "" Then
    MsgBox "No body, no message." & vbNewLine & vbNewLine & _
         "Quitting...", vbCritical, "I Ain't Got No-Body!"
    Exit Function
End If

 ' Check to make sure the file exists...
If fso.FileExists(BodyFile$) = False Then
    MsgBox "The body file isn't where you say it is. " & vbNewLine & vbNewLine & _
           "Quitting...", vbCritical, "I Ain't Got No-Body!"
    Exit Function
End If

   ' Since we got a file, we can open it up.
    Set MyBody = fso.OpenTextFile(BodyFile, ForReading, False, TristateUseDefault)

   ' and read it into a variable.
    MyBodyText = MyBody.ReadAll

   ' and close the file.
    MyBody.Close

   ' Now, we open Outlook for our own device..
    Set MyOutlook = New Outlook.Application


 ' Set up the database and query connections

    Set db = CurrentDb()

    Set MailList = db.OpenRecordset("MyEmailAddresses")

 ' now, this is the meat and potatoes.
 ' this is where we loop through our list of addresses,
 ' adding them to e-mails and sending them.

    Do Until MailList.EOF

        ' This creates the e-mail

        Set MyMail = MyOutlook.CreateItem(olMailItem)

            ' This addresses it
            MyMail.To = MailList("email")

            'This gives it a subject
            MyMail.Subject = Subjectline$

            'This gives it the body
            MyMail.Body = MyBodyText


            'If you want to send an attachment
            'uncomment the following line

            MyMail.Attachments.Add "c:\dbgout.txt", olByValue, 1, "My Displayname"
            MyMail.Attachments.Add "c:\dbgout.txt", olByValue, 1, "My Displayname2"

            ' To briefly describe:
            ' "c:\myfile.txt" = the file you want to attach
            '
            ' olByVaue = how to pass the file. olByValue attaches it, olByReference creates a shortcut.
            ' the shortcut only works if the file is available locally (via mapped or local drive)
            '
            ' 1 = the position in the outlook message where to attachment goes. This is ignored by most
            ' other mailers, so you might want to ignore it too. Using 1 puts the attachment
            ' first in line.
            '
            ' "My Displayname" = If you don't want the attachment's icon string to be "c:\myfile.txt" you
            ' can use this property to change it to something useful, i.e. "4th Qtr Report"



            'This sends it!
            MyMail.Send

            'Some people have asked how to see the e-mail
            'instead of automaticially sending it.
            'Uncomment the next line
            'And comment the "MyMail.Send" line above this.

            'MyMail.Display



    'And on to the next one...
    MailList.MoveNext

Loop

 'Cleanup after ourselves

Set MyMail = Nothing


'Uncomment the next line if you want Outlook to shut down when its done.
'Otherwise, it will stay running.

'MyOutlook.Quit
Set MyOutlook = Nothing

MailList.Close
Set MailList = Nothing
db.Close
Set db = Nothing

End Function

 
Old August 26th, 2004, 04:12 AM
Authorized User
 
Join Date: Jun 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi - Thanks for your advice, I'll give it a go over the weekend. The code module looks great and it's definitely more flexible than my original effort.

Cheers

William
 
Old May 11th, 2006, 02:34 AM
Registered User
 
Join Date: Dec 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

what I want to get deleviery report from recevier's end. i.e whether my mail has been deleviered or not.






Similar Threads
Thread Thread Starter Forum Replies Last Post
how to get reports in crystal reports using ASP3.0 candy133 Classic ASP Basics 2 January 26th, 2006 08:26 AM
Comparitive Reports in Crystal Reports tarunm Crystal Reports 1 January 21st, 2006 01:08 AM
Email Sending Reports rgerald Access VBA 5 May 3rd, 2005 01:29 PM
comparision among crystal reports and Data reports avats Crystal Reports 0 April 13th, 2005 01:01 PM
How to create/design reports with crystal reports BassmaniaQ Crystal Reports 0 December 14th, 2004 04:58 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.