Results 1 to 4 of 4
  1. #1
    4 Star Lounger
    Join Date
    Mar 2005
    Location
    Leicestershire, United Kingdom
    Posts
    506
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Attaching a file to a email in access? (2000)

    Hi

    I am trying to construct a message in access, but also attach a file to the e-mail (PDF), ny ideas on how to do this?
    Best Regards,

    Luke

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

    Re: Attaching a file to a email in access? (2000)

    You'll need to control Outlook through Automation. Search for Outlook.Application in this forum for previous threads about this subject. For example the one starting at <post:=383,300>post 383,300</post:>.

  3. #3
    4 Star Lounger
    Join Date
    Mar 2005
    Location
    Leicestershire, United Kingdom
    Posts
    506
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Attaching a file to a email in access? (2000)

    Managed to get so far:

    Dim ol As New Outlook.Application
    Dim ns As Outlook.NameSpace
    Dim newMail As Outlook.MailItem
    Dim varsalesid
    Dim varaddress
    Dim strsubject
    Dim strBody
    Dim strname
    Dim strvaluer
    Dim strvaldate
    Dim strvaltime
    Dim strnegname
    Dim strnegtitle
    Dim strattachment



    strname = IIf([Surname2] = [Surname1], [Title1] & " and " & [Title2] & " " & [Surname1], [Title1] & " " & [Surname1] & IIf(IsNull([Surname2]), "", " and " & [Title2] & " " & [Surname2]))
    strvaluer = DLookup("[ValName]", "tblValuer", "ValuerID=" & Me!ValuerID)
    strvaldate = DisplayDate(Me.ValuationDate)
    strvaltime = Format(Me.AptTime, "Short Time")
    varaddress = Me.EmailAddress
    strnegname = DLookup("[capsname]", "tblSalesman", "salesid=" & Me!SalesID)
    strnegtitle = DLookup("[jobtitle]", "tblsalesman", "salesid=" & Me!SalesID)
    Str Attachment = "c:newsletter.pdf"

    'Return a reference to the MAPI layer.
    Set ns = ol.GetNamespace("MAPI")

    'Create a new mail message item.
    Set newMail = ol.CreateItem(olMailItem)
    With newMail
    'Add the subject of the mail message.
    .Subject = VHouseNo & " " & VStreetName & ", " & VArea & " - " & "Property Valuation"
    'Create some body text.
    .Body = "Dear " & strname & vbCrLf & vbCrLf & "Thank you for inviting our valuer, " & strvaluer & " to your home to carry out a market valuation on your property. I can confirm the appointment has been arranged for " & strvaldate & " at " & strvaltime & "." & vbCrLf & vbCrLf & "Should you require any further information or assistance please do not hesitate to contact us." & vbCrLf & vbCrLf & "Yours sincerely" & vbCrLf & vbCrLf & strnegname & vbCrLf & strnegtitle & vbCrLf

    'Add a recipient and test to make sure that the
    'address is valid using the Resolve method.
    With .Recipients.Add(Me.EmailAddress)
    .Type = olTo
    If Not .Resolve Then
    MsgBox "Unable to resolve address.", vbInformation
    Exit Sub
    End If
    End With

    'Attach a file as a link with an icon.
    With .Attachments.Add_
    strattachment , olByReference

    .DisplayName = "Training info"
    End With

    'Send the mail message.
    .Send
    End With

    'Release memory.
    Set ol = Nothing
    Set ns = Nothing
    Set newMail = Nothing

    End Sub

    But i cannot get the attachment section to function property, any ideas?
    Best Regards,

    Luke

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

    Re: Attaching a file to a email in access? (2000)

    There is a superfluous space in the line

    Str Attachment = ...

    It should be

    strAttachment = ...

    By the way, I don't think it is a good idea to try to send a link to a file on your C: disk. You should only send a link to a file that is stored in a location available to all recipients; otherwise you should send the file itself.

Posting Permissions

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