Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    3 Star Lounger
    Join Date
    Nov 2001
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Send Email with/out attachment (Access 2000)

    How can I send an email through Access?
    I understand the docmd.sendobject method, but I do not want to send a form, report, etc.
    I wish to send an email to the address specified in the "cemail" field, with text based on the "E_txt" field and the subject based on the "esub" field.
    As an added benefit to my users, if they check the "e_attach" check box, they can send the attachment specified in the "letter" hypertext field.
    I can't seem to find any mention of this in the help file - so any help is gratefully welcome!

    Thanks in advance!

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Send Email with/out attachment (Access 2000)

    If you want to send an e-mail without an attachment, you can use

    DoCmd.SendObject ObjectType:=acSendNoObject, To:=Me.cemail, Subject:=esub, MessageText:=E_txt

    If you want to include an attachment, you'll have to do it completely differently. SendObject doesn't support attachments other than database objects. If you use Outlook, you can use Automation to control Outlook from Access in VBA to create a new e-mail, add an attachment etc.
    Because of the draconian security measures in Outlook, there are some extra things you have to do to make it work smoothly.
    It is possible, but it takes some work, and requires that you are comfortable with Access and Outlook VBA.

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Wetherby, Yorkshire, England
    Posts
    283
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Send Email with/out attachment (Access 2000)

    This is a truncated version of automation code I put together. You will need to Dim all the variables and change the table and field names but it will get you started.

    If I'm trying to automate something in Office I usually find Helen Feddema has already worked out something similar that I can adapt.

    Set appOutlook = CreateObject("Outlook.Application")
    Set nms = appOutlook.GetNamespace("MAPI")
    Set pfld = nms.GetDefaultFolder(olFolderOutbox)
    Set itms = pfld.Items
    Set rst = CurrentDb.OpenRecordset("MyEmailTable")

    With rst
    strAddress = Nz(!Address)
    strSubject = Nz(!Heading)
    strBody = Nz(!Message)
    strLetter = Nz(!Title)
    strAtt = "MyFilename"

    End With
    Set itm = itms.Add("IPM.Note")

    With itm
    .Body = strBody & NL & NL & strSign
    .Subject = strSubject
    .To = strAddress
    .Attachments.Add strAtt
    .Send
    End With

    Hope it helps to get you sorted.

    Peter

  4. #4
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Wetherby, Yorkshire, England
    Posts
    283
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Send Email with/out attachment (Access 2000)

    Sorry, should probably explain that I use NL instead of Chr(10) for new lines
    Peter

  5. #5
    3 Star Lounger
    Join Date
    Nov 2001
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Send Email with/out attachment (Access 2000)

    Thanks Peter and Hans.

    I'm using Outlook Express and although I've dimmed the variable as so:

    Dim appOutlook As Object

    I'm getting the following error message:
    "Runtime error 429 ActiveX component can't create object"
    at the line:

    Set appOutlook = CreateObject("Outlook.Application")

    I tried variations such as Outlook Express.Application and even OutlookExpress.Application but all had the same result.
    Any suggestions as to what the problem is?

    Thanks again for your time.

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Send Email with/out attachment (Access 2000)

    Outlook Express doesn't have an exposed object model, so you can't control it using Automation the way you can control Outlook.

    I don't know how to do this with Outlook Express; although you can create a command line to send mail from Outlook Express, there is no switch to attach a file as far as I know.

  7. #7
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Wetherby, Yorkshire, England
    Posts
    283
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Send Email with/out attachment (Access 2000)

    I assumed you were using Outlook rather than Outlook Express and you know what they say about making assumptions.
    Sorry, can't help you with OE.
    Peter

  8. #8
    3 Star Lounger
    Join Date
    Nov 2001
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Send Email with/out attachment (Access 2000)

    Thanks Hans and Peter for your time, I will work around what you have said.

  9. #9
    Lounger
    Join Date
    Jan 2003
    Location
    Herndon, Virginia, USA
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Send Email with/out attachment (Access 2000)

    Hi, you can use this code to send e-mails using the MAPI reference library. I haven't tested it with Outlook Express, but it should work. The really nice thing about this code is that you don't need to know the e-mail software ahead of time (like Outlook) and you don't have to add any references in the database since it uses late binding.

    The code originally came from Bart (one of the loungers here). I translated some of his comments and added the ability to include attachments (up to two, although it's easy to add more by editing the code). I couldn't figure out how to run this new code by him first, so I hope he doesn't mind my edits or reposting of it (since I also couldn't find the original post without the search capability).

    The code is in the attached file.

    Brent
    Attached Files Attached Files

  10. #10
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Send Email with/out attachment (Access 2000)

    I found this post when searching for a solution. I want to try to programmatically send emails with attachments without using Outlook.

    So I have copies all this code into a new class module, created a form with the required controls and a send button.

    The first time I clicked it complained that I wasn't using Outlook, but I have not been able to explore that because on every subsequent time it stops at:

    Set clsMAPITest = New clsMAPI

    and when I explore further it is because the initialize method can't execute this line.

    Set objMySes = CreateObject("MAPI.Session")

    I have just done some more testing, and can get it to work by setting Outlook as my default mail client.

    Can anyone tell me if this code should work with any email program, or just Outlook. (The setting where I am looking to use it uses Eudora)
    Regards
    John



  11. #11
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    Vancouver, Br. Columbia, Canada
    Posts
    632
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Send Email with/out attachment (Access 2000)

    You can avoid Outlook entirely using the free email control at http://www.aspemail.com/
    --------------------------------------------------
    Jack MacDonald
    Vancouver, Canada

  12. #12
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Send Email with/out attachment (Access 2000)

    Thanks, that looks interesting, but i don't think I can use it in the current situation.

    My client works for a university and is not going to be allowed to install email dll's and exe's on the server.
    (My reading of the documentation says this is needed.)

    I need a solution that works entirely within the individual PC.

    In the post I was trying to use, Brent said that the solution he was posting did not need Outlook, so I hoped it would provide what I want.
    Regards
    John



  13. #13
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    Vancouver, Br. Columbia, Canada
    Posts
    632
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Send Email with/out attachment (Access 2000)

    Installation on server is required only if he is doing a server-based application, and wants remote users to send email via the web app. If it is entirely workstation-based, then he would not need to install anything on the server, Of course, he may also be prohibitted from installing stuff on the workstation...
    --------------------------------------------------
    Jack MacDonald
    Vancouver, Canada

  14. #14
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Send Email with/out attachment (Access 2000)

    Thanks

    I will download it and experiment with it and see how it goes.

    Even if I can't use it for this project, it is worth knowing about for others.

    John
    Regards
    John



  15. #15
    3 Star Lounger
    Join Date
    Nov 2001
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Send Email with/out attachment (Access 2000)

    John,
    You will need vastly different code for an email client such as Lotus Notes. When I distribute an application to my clients which requires their clients to email them, I include a quick dialog box which requires the user to select either Lotus Notes or Outlook as their email client.
    There are some very helpful threads on this here - do a search (as I did originally) and you'll find what you need.
    Cheers!

Page 1 of 2 12 LastLast

Posting Permissions

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