Consulting

Results 1 to 7 of 7

Thread: Send Email Attachment from within Access

  1. #1
    VBAX Newbie
    Joined
    Jul 2005
    Posts
    3
    Location

    Question Send Email Attachment from within Access

    Is there any way to send an email with an attachment from within my code. I don't want to send an access object. I want to send a file that is saved on my system. is this possible?

    Thank you

  2. #2
    BoardCoder
    Licensed Coder
    VBAX Expert mark007's Avatar
    Joined
    May 2004
    Location
    Leeds, UK
    Posts
    622
    Location
    Sure, are you wanting to send it through MS Outlook or another program?
    "Computers are useless. They can only give you answers." - Pablo Picasso
    Mark Rowlinson FIA | The Code Net

  3. #3
    VBAX Newbie
    Joined
    Jul 2005
    Posts
    3
    Location
    I've assumed I'd have to send it with Outlook so that would be fine.

  4. #4
    VBAX Newbie
    Joined
    Jul 2005
    Posts
    3
    Location
    I've assumed I'd have to send it with Outlook so that would be fine.

  5. #5
    VBAX Expert xCav8r's Avatar
    Joined
    May 2005
    Location
    Minneapolis, MN, USA
    Posts
    912
    Location
    I've never tried automating outlook, but if you're talking about an attachment that's an office doc, then you can probably use send mail from that app and control it from Access. Alternatively, you might find this helpful...http://support.microsoft.com/default...b;en-us;161088

  6. #6
    BoardCoder
    Licensed Coder VBAX Expert mark007's Avatar
    Joined
    May 2004
    Location
    Leeds, UK
    Posts
    622
    Location
    To automate Outlook you can use the following:

    [vba]

    Sub SendMail()

    Dim olApp As Outlook.Application
    Dim olMail As Outlook.MailItem

    'get application
    On Error Resume Next
    Set olApp = GetObject(, "Outlook.Application")
    If olApp Is Nothing Then Set olApp = New Outlook.Application
    On Error GoTo 0

    Set olMail = olApp.CreateItem(olMailItem)
    With olMail
    .Subject = "My email with attachment"
    .Recipients.Add "name@host.com"
    .Attachments.Add "c:\test.txt"
    .Body = "Here is an email"
    .Display 'This will display the message for you to check and send yourself
    '.Send ' This will send the message straight away
    End With


    End Sub
    [/vba]

    Note that for versiosn of Outlook above 2000 you will get security warnings that a program is trying to control it which can make it awkward to use.

    "Computers are useless. They can only give you answers." - Pablo Picasso
    Mark Rowlinson FIA | The Code Net

  7. #7
    VBAX Expert xCav8r's Avatar
    Joined
    May 2005
    Location
    Minneapolis, MN, USA
    Posts
    912
    Location
    Mark, if that's not already a KB entry, you should submit it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •