Consulting

Results 1 to 6 of 6

Thread: email an attached file using MS Access

  1. #1

    email an attached file using MS Access

    A customer needs to email various attachments that have not been created in MS Access. He wants to use his Access system which includes his entire customer base with email addresses to do the mailing.

    So far I've done the following legwork: created a form with a built in MS Explorer function so he can easily select the file he wishes to send, along with a place for him to key some text and the ability to easily select the customer/customers to receive the email.

    That's about as far as I've gotten. I tried putting a command button on my form to use the DoCmd.SendObject statement, but that is obviously a mistake. No where that I can tell to put the object path for the attachment.

    I've rarely used email in an Access system, so it's quite possible I'm just ignorant.

    Any ideas?

  2. #2
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    Hi, the docmd object is not very good at sending attachments.
    Here is the code that I used, it should have Error Trapping added,

    Dim objOutlook  As New Outlook.Application  ' outlook object
        Dim objMessage  As MailItem, strAttach As String    ' outlook mail message
       Dim Subject As String, Body As String, EmailAddress As String
        EmailAddress = Me.EmailAddress
        strAttach = Me.Attachment
                Set objMessage = objOutlook.CreateItem(olMailItem)
                With objMessage
                    .To = EmailAddress
                    .Subject = "Test Send"
                    .Body = "This is a Test"
                    .Attachments.Add strAttach
                    .DisplayName = "Joe Bloggs"
                    .Send
                End With
        Set objOutlook = Nothing
        Set objMessage = Nothing

  3. #3
    Quote Originally Posted by OBP View Post
    Hi, the docmd object is not very good at sending attachments.
    Here is the code that I used, it should have Error Trapping added,

    Dim objOutlook  As New Outlook.Application  ' outlook object
        Dim objMessage  As MailItem, strAttach As String    ' outlook mail message
       Dim Subject As String, Body As String, EmailAddress As String
        EmailAddress = Me.EmailAddress
        strAttach = Me.Attachment
                Set objMessage = objOutlook.CreateItem(olMailItem)
                With objMessage
                    .To = EmailAddress
                    .Subject = "Test Send"
                    .Body = "This is a Test"
                    .Attachments.Add strAttach
                    .DisplayName = "Joe Bloggs"
                    .Send
                End With
        Set objOutlook = Nothing
        Set objMessage = Nothing
    I've tried adding your code but it bumps up against a
    User_Defined type not defined
    error. Am I missing a reference library? Do I need to declare the Outlook.Application elsewhere?
    I am using Access 365.

  4. #4
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    Yes you will definitely need to set the Library References to Outlook.

  5. #5
    Quote Originally Posted by OBP View Post
    Yes you will definitely need to set the Library References to Outlook.
    .did that up front, still got the error message listed above.

  6. #6
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    Have you got an Equivelent of Me.EmailAddress?
    That comes from the Form that I use to test various types of emailing.
    Here is the database.
    Attached Files Attached Files

Posting Permissions

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