Results 1 to 4 of 4
  1. #1
    scoe is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2013
    Posts
    91

    Send email with Attachment

    Ihope someone can tell me what is wrong with this code.... I have a form that selects a student (Student ID and Student Name), organisation and email and I have a file that contains CV's saved as word documents (docx) using the student ID as the name.
    What I am trying to do is use the fields on the form to open an email to the organisation and send the CV as an attachment. The code is struggling to find the document attachment.

    [Private Sub Command95_Click()
    Dim strPath As String
    Dim strFilter As String
    Dim strFile As String
    strPath = "L:QLS Reports\Work Experience\CV\"
    strName = Me.[Student ID]
    strFilter = "*.docx"
    strFile = Dir(strPath & strName & strFilter)
    Set appOutLook = CreateObject("Outlook.Application")
    Set MailOutLook = appOutLook.CreateItem(olMailItem)
    Const olFormatHTML = 2
    With MailOutLook
    .BodyFormat = olFormatHTML
    .To = [Forms]![Email CV].[OrgEmail1]
    .cc = ""
    .bcc = ""
    .Subject = [Forms]![Email CV].[StuName]
    .HTMLBody = "Please find CV attached for the above student"



    Attachments.Add (strPath & strFile)

    Display
    End With
    End Sub]

    Thank you

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,527
    dont know if it matters but the attache code that works is:
    .Attachments.Add vFile, olByValue, 1

    also , not sure of the result of : Dir(strPath & strName & strFilter)
    If you are attaching >1 file, I would cycle thru the directory list via ("Scripting.FileSystemObject")

    [code]

    'import all files in folder
    '------------------
    Public Sub ImportAllFiles(ByVal pvDir)
    '------------------
    Dim vFil, vTargT
    Dim i As Integer
    Dim sTbl As String, sSql As String
    Dim vSheet, oFolder, oFile

    On Error GoTo errImp
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set oFolder = fso.GetFolder(pvDir)
    For Each oFile In oFolder.Files

    If InStr(oFile, ".xls") > 0 Then 'only excel files, change as needed
    vFil = pvDir & oFile.Name
    'attach VFIL TO email here
    End If
    Next 'file
    End Select
    Set colSheets = Nothing
    Set oFile = Nothing
    Set oFolder = Nothing
    Exit Sub
    errImp:
    MsgBox Err.Description, vbCritical, "ImportAllXLFilesAndSheets()" & Err
    Exit Sub
    Resume
    End Sub
    [/code'

  3. #3
    scoe is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2013
    Posts
    91
    Thank you I'll give it a go

  4. #4
    scoe is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2013
    Posts
    91
    Thank you for your help, I have solved this by weaking the code as below
    [
    strPath = "L:\QLS Reports\WORK EXPERIENCE\CV\" & [Student ID]
    strFilter = ".docx"
    strFile = (strPath & strFilter)
    .Attachments.Add (strFile)

Please reply to this thread with any new information or opinions.

Similar Threads

  1. How to send email without attachment
    By behnam in forum Programming
    Replies: 3
    Last Post: 07-30-2014, 08:24 AM
  2. Send email in Outlook with attachment
    By kelkan in forum Programming
    Replies: 1
    Last Post: 02-01-2013, 10:31 PM
  3. Send Email with Attachment VBA Code
    By kevins in forum Programming
    Replies: 2
    Last Post: 10-03-2012, 01:21 PM
  4. Replies: 1
    Last Post: 03-09-2011, 08:54 AM
  5. Beginner trying to send email with attachment
    By ahm in forum Programming
    Replies: 2
    Last Post: 03-24-2009, 08:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums