VB Script to Send Multiple Attachments via Email


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: VB Script to Send Multiple Attachments via Email

  1. #1
    Join Date
    Apr 2010
    Posts
    8

    VB Script to Send Multiple Attachments via Email

    Help! I'm hoping that someone can point me to a VB script that will do a fairly simple task.

    I have a Microsoft Access table that lists the full directory path for a number of files.

    I am looking for a script that will create a new email message in Outlook that attaches each of the files listed in the table. The user will then input the recipient and subject, and can send the email from Outlook.

    Any help would be greatly appreciated! Thanks in advance.

  2. #2
    Join Date
    Apr 2010
    Posts
    8

    Loop not working

    Ok, I've written some code that mostly works, but here's the problem: I have 3 files that come up in the query below. I want the code to insert those 3 files into the email as attachments. The code is inserting the first file 3 times, instead or inserting each of the 3 files. What am I doing wrong with my loop?

    Private Sub EmailMarkedDocuments_Click()
    Dim MyDB As Database
    Dim MyRS As Recordset
    Dim objOutlook As Outlook.Application
    Dim objOutlookMsg As Outlook.MailItem
    Dim objOutlookAttach As Outlook.Attachment
    Dim TheAttachment As String

    Me.CourtClipResults.Requery
    If (DCount("[Description]", "CheckForMarkedQuery") < 1) Then
    MsgBox "You must check at least one document in order to send the email.", 0, "CW Case Management System"
    Else

    Set objOutlook = CreateObject("Outlook.Application")
    Set objOutlookMsg = objOutlook.CreateItem(0) 'olMailItem
    Set MyDB = CurrentDb
    Set MyRS = MyDB.OpenRecordset("CheckForMarkedQuery")
    TheAttachment = MyRS![FilePath]
    MyRS.MoveFirst

    With objOutlookMsg

    .Subject = "Documents from Colt / Wallerstein LLP for Matter: " & (DLookup("[MatterName]", "MatterList", "ID=Forms!CourtClipForm!CourtClipMatter"))
    .HTMLBody = "Please see the attached documents."


    Do Until MyRS.EOF
    MyRS.MoveNext
    Set objOutlookAttach = .Attachments.Add(TheAttachment)

    Loop
    End With

    objOutlookMsg.Display

    End If

    End Sub

Similar Threads

  1. They created J#, why couldn't they do VB#?
    By Thomas Eyde in forum .NET
    Replies: 290
    Last Post: 12-22-2001, 02:13 PM
  2. send a form to an email
    By Ruth in forum ASP.NET
    Replies: 3
    Last Post: 02-06-2001, 12:58 AM
  3. Replies: 0
    Last Post: 01-23-2001, 07:55 PM
  4. Replies: 0
    Last Post: 01-22-2001, 03:59 PM
  5. Can ASP send an email confirmation through code?
    By John Knoop in forum ASP.NET
    Replies: 0
    Last Post: 11-15-2000, 03:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center