Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2003

    Question Unanswered: VB Access Email including link or attachment

    Hi all,

    I've currently got a vb script that sends e-mails out to a number of people within a set list. The details of the email depend on whats within the above form.

    All works exactly how I want it to, however someone has now asked me to send an attachment with these e-mails. I'm using the DoCmd.SendObject method so I am aware that I cannot attach non-access documents using this method, however, rather than having to re-write my entire script, is it possible to create links in the email using this sendobject method?

    This is an example of the method that I am using.

    DoCmd.SendObject , , , , "", , DimSubject, vbCrLf _
    & "Dear " & Me.List01.Column(3) _
    & vbCrLf _
    & vbCrLf _
    & "Please find attached documentation for usage"

    Can anyone help?

  2. #2
    Join Date
    Sep 2005
    Quote Originally Posted by christyxo
    ....I'm using the DoCmd.SendObject method so I am aware that I cannot attach non-access documents using this method, ...
    Not sure this is entirely true. I routinely send queries formatted as excel attachments. Here's the syntax of the of the sendobject command

    expression.SendObject(ObjectType, ObjectName, OutputFormat, To, Cc, Bcc, Subject, MessageText, EditMessage, TemplateFile)

    In my situation objectype=acQuery, objectname="myqueryname", outputformat=acformatXLS

    You didn't specify what type of attachments you want to include but maybe you can use my example as a starting point.

  3. #3
    Join Date
    Oct 2003
    No, sorry, I'm trying to bring an outside attachment into the e-mail. I understand how to send .snp/.rtf etc but what I'm trying to achieve is to send out a warning message to people within a list, and to attach an existing document from on our network to this e-mail.

    I appreciate your help but unless I can modify it to pick up a document (in this case its a .dot template), as opposed to an object from within the database, I don't think it will help me.


  4. #4
    Join Date
    Dec 2002
    Préverenges, Switzerland
    here's an outline of a simple mailer using Outlook: make a module and copy/paste.

    the call is:
    if izymailer(mode, to, subject, bodytext, "c:\here\this.txt") then
    'mail was ok
    'it wasn't


    Option Explicit
    '/// demo of late-bind to Outlook to send mail (possibly with attached file)
    '/// code is late-bind so should be independent of Access/Outlook versions
    '///we are late-binding so need some outlook constants defined locally
    Const izyMailerCstOLMailItem = 0
    Public Enum izyMailerMode
        izyMailerMode_Draft = 1
        izyMailerMode_Display = 2
        izyMailerMode_Send = 3
    End Enum
    Public Function izyMailer(isMode As izyMailerMode, isTo As String, isSubj As String, isBody As String, Optional isFile As String = "NONE") As Boolean
        '   isMode = izyMailerMode_Draft, izyMailerMode_Display, izyMailerMode_Send
        '   isTo    the recipient's mail address
        '   isSubj  the mail subject
        '   isBody  the mail body text
        '   isFile  the drive:/path/name.extension of a file to attach
        '   on error FALSE, else TRUE
        'this code does not check that the function was called with correct parameters
        'and that's something you definitely want to add!
        On Error GoTo err_izyMailer
        Dim objOutlook As Object
        Dim objOutMail As Object
        Dim objOutFile As Object
        '/// instantiate outlook objects
        'this will parasite off an existing outlook session if there is one
        'else will start outlook (and close outlook when done if it was not open). 
        Set objOutlook = CreateObject("Outlook.Application")
        Set objOutMail = objOutlook.CreateItem(izyMailerCstOLMailItem)
        Set objOutFile = objOutMail.Attachments
        With objOutMail
            .Subject = isSubj
            .Body = isBody
            .To = isTo
            '/// this code does not handle CC, BCC etc. use object-browser in Outlook (or guess!)
        End With
        '/// this code does not check if the specified attach file actually exists       
        If Not isFile = "NONE" Then
            '/// if you might have multiple attachments, modify the code:
            'use a delimiter in the parameter and split(<delimiter>) 
            'and loop through the resulting array with similar .Add code
            Set objOutFile = objOutMail.Attachments
            objOutFile.Add isFile
        End If
        If isMode = izyMailerMode_Display Then                      'show on screen
            objOutMail.Save                                         'save as draft
            If isMode = izyMailerMode_Send Then                     'and possibly send
            End If
        End If
        izyMailer = True                                            'success return
        On Error Resume Next                        'release all objects
        Set objOutFile = Nothing
        Set objOutMail = Nothing
        Set objOutlook = Nothing
        Exit Function                               'and exit
    err_izyMailer:                                  'generic error handling
        izyMailer = False                           'failure return
        MsgBox Err.Description, vbCritical, "izyMailer Error"
        Resume exit_izyMailer
    End Function
    currently using SS 2008R2

Posting Permissions

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