Results 1 to 7 of 7
  1. #1
    Join Date
    Jun 2002
    Posts
    173

    Unanswered: email attachments with Access and Outlook

    I'm using the following code to simply bring up a new outlook email message with an attachment. It's get's the full document path for the attachment from the field "emaildocslist". I currently have my form setup so that multiple path names are able to be added and seperated by a ";". This code won't except it though. Only works when one item is in the field. Are there any other ways to have it accept multiple attachments?



    Private Sub Command72_Click()
    Dim i As Integer
    Dim appOutl As Outlook.Application
    Dim maiMail As MailItem
    Dim recMEssage As Recipient
    'Dim ns As Outlook.NameSpace

    Set appOutl = New Outlook.Application
    'Set ns = appOutl.GetNamespace("MAPI")
    'provide the profilename, if no password leave blank
    'ns.Logon "Profile Name Here", , False, True
    Set maiMail = appOutl.CreateItem(olMailItem)
    With maiMail
    'Optional test against addressbook is ' boorecip = .Recipients.ResolveAll
    'You might want to insert a conditinal here if boorecip=False
    '.Subject = "Testing document"
    'get the attachments file name and path from the array and attach it
    'if are going to display it to address it don't need the recipients.add
    'you will need this line for each recipient, unless using a group
    '.Recipients.Add ("user@domain.com")

    .Attachments.Add (emaildocslist)

    'You do not need .body if you are going to type the msg .Body = "Created by vba code"

    'Using .Send instead of .Display will send the msg without displaying it
    .Display
    End With
    Set appOutl = Nothing
    Set maiMail = Nothing
    Set recMEssage = Nothing
    End Sub

  2. #2
    Join Date
    Jul 2003
    Location
    Italy
    Posts
    139
    If your db runs under w2k why don't you use CDO?

    See: http://www.mvps.org/access/modules/mdl0019.htm
    Marco
    ---Do not send e-mail---
    "New Big Bang Theory: God said unzip universe"

  3. #3
    Join Date
    Jun 2002
    Posts
    173
    I have the database running a couple of different windows platforms.

  4. #4
    Join Date
    Jul 2003
    Location
    Italy
    Posts
    139
    Which ones?
    Marco
    ---Do not send e-mail---
    "New Big Bang Theory: God said unzip universe"

  5. #5
    Join Date
    Jun 2002
    Posts
    173
    ME, W2K, XP

  6. #6
    Join Date
    Jul 2003
    Location
    Italy
    Posts
    139
    I believe that (with the exclusion of ME) you can use CDONTS.

    Anyway I did a quick search around my docs and found that probably your problem has no solution. Even the SendObject has such a limitation (only one attachment).

    I had the same problem, so I split the db, put the be on a server and run CDONTS... but again I put the attachment in the body of the e-mail.

    Hope you find a solution from someone more expert then me.
    Marco
    ---Do not send e-mail---
    "New Big Bang Theory: God said unzip universe"

  7. #7
    Join Date
    Jun 2002
    Posts
    173
    I've tried an array. But get a "run time error 5, invalid procedure call or argument". Then highlights " Set objOutlookAttach = .Attachments.Add(Left(strWholePath, vPos - 1))" in the code.

    Private Sub Command77_Click()
    Dim i As Integer
    Dim appOutl As Outlook.Application
    Dim maiMail As MailItem
    Dim recMEssage As Recipient
    Dim strWholePath As String
    Dim vPos As Variant
    Dim vLast As Variant
    Dim objOutlookAttach As Outlook.Attachment

    Set appOutl = New Outlook.Application
    Set maiMail = appOutl.CreateItem(olMailItem)
    With maiMail


    strWholePath = Me.emaildocslist 'change to your text box name



    If Not IsNull(strWholePath) Then
    vPos = InStr(1, strWholePath, ";", vbTextCompare)
    vLast = vPos
    Set objOutlookAttach = .Attachments.Add(Left(strWholePath, vPos - 1))

    Do While vLast <> Len(strWholePath)
    vPos = InStr(vPos + 1, strWholePath, ";", vbTextCompare)
    Set objOutlookAttach = .Attachments.Add(Mid(strWholePath, vLast + 1, vPos - vLast - 1))
    vLast = vPos
    Loop
    End If

    .Display
    End With
    Set appOutl = Nothing
    Set maiMail = Nothing
    Set recMEssage = Nothing

    End Sub

Posting Permissions

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