Results 1 to 9 of 9
  1. #1
    Join Date
    Aug 2006
    Posts
    559

    Unanswered: eMail from Outlook error

    Ok, so I found a way to email from Access through Outlook. I found it from blueclaw-db.com. I tested it through their actual db, it worked fine. When I tried to add it to mine (copied the code behind the 'send' button) I get an error with the following code. I don't understand because I copied the code from theirs, kinda know what its doing, made sure all the ActiveX controls were checked, just redesigned the form.

    Any ideas? (It highlights the "Dim appOutlook As Outlook.Application" line)

    Code:
    rivate Sub Command4_Click()
    
            Dim mess_body As String
            Dim appOutLook As Outlook.Application
            Dim MailOutLook As Outlook.MailItem
            Set appOutLook = CreateObject("Outlook.Application")
            Set MailOutLook = appOutLook.CreateItem(olMailItem)
                
                Set appOutLook = CreateObject("Outlook.Application")
                Set MailOutLook = appOutLook.CreateItem(olMailItem)
                With MailOutLook
                .BodyFormat = olFormatRichText
                .To = Me.Email_Address
                .Subject = Me.Mess_Subject
                .HTMLBody = Me.Mess_Text
                If Left(Me.Mail_Attachment_Path, 1) <> "<" Then
                    .Attachments.Add (Me.Mail_Attachment_Path)
                End If
                '.DeleteAfterSubmit = True   'This would let Outlook send th note without storing it in your sent bin
                .Send
                End With
                'MsgBox MailOutLook.Body
                Exit Sub
    email_error:
                MsgBox "An error was encountered." & vbCrLf & "The error message is: " & Err.Description
                Resume Error_out
    Error_out:
    
    End Sub

  2. #2
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    your code is attempting an early-bind to Outlook.
    do you have a reference set to Outlook?

    izy
    currently using SS 2008R2

  3. #3
    Join Date
    Aug 2006
    Posts
    559
    Quote Originally Posted by izyrider
    your code is attempting an early-bind to Outlook.
    do you have a reference set to Outlook?

    izy
    No, I don't have that. I don't think. Probably don't, actually, pretty positive I don't.

    Splain? I looked through the entire set of code on the example that I found from blueclaw, didn't see anything.

  4. #4
    Join Date
    Jun 2007
    Location
    Maitland NSW,Australia
    Posts
    388

    Email

    To email I use the DoCmd.SendObject command. I send report in the snapshot format and queries in spreadsheet format.

    An example for reports
    stDocName = "rpt_name"

    DoCmd.SendObject acSendReport, stDocName, "snapshotformat", , , , "Sample Report"

    Outlook opens and the user can enter the To, CC and add a message if required.

  5. #5
    Join Date
    Aug 2006
    Posts
    559
    Poppa,

    So what you're saying, is that may be easier than what I'm doing?

  6. #6
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    Alt-F11 (open code window)
    code window menu: Tools/References
    ...scroll down to Outlook ...its under 'MS'
    ...tick it.

    now it works.

    izy
    currently using SS 2008R2

  7. #7
    Join Date
    Jun 2007
    Location
    Maitland NSW,Australia
    Posts
    388

    Email

    Grafixx01

    Yes. It is easier and quicker.

    Run send_email in the module mod_send_email in the attached database.

    If Outlook is closed then Access opens Outlook ready to send the email.
    Attached Files Attached Files

  8. #8
    Join Date
    Aug 2006
    Posts
    559
    Ok, I'm going to take a look at that too. Cause I was just going to try and see how to program a "browse" button in the form for the user to search for the attachment, if any. But then again, I was going to limit the eMail address to ONLY those listed in the db so I am going to look at the one you submitted here and also mine to figure out which would be best.

    Thanks for everything.

  9. #9
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    SendObject, while simpler, will not send attachments other than Access objects. You'll need to use your original code if you want to simply select a file to attach.
    Paul

Posting Permissions

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