Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Automatic email attachment of files
Greg Beben 
    
15 years ago
Richard, now that we can attach any file to the database with the LaunchCD function, is there an easy way to code a button so that, when clicked, the given file is attached to an email?   Like you can right click a file from Windows Explorer and choose "Send To" then "Mail recipient", and your email client opens with the file attached to a new email.


Reply from Richard Rost:

Yes. Here is a function that I wrote a few years ago to send a message from Access using Outlook that allows up to 6 file attachments. I was planning on including this in an upcoming lesson, but you should be able to figure it out:


Public Sub SendMessageViaOutlook(MessageTO As String, _
                                MessageSubject As String, _
                                MessageBody As String, _
                                Optional MessageCC As String = "", _
                                Optional MessageBCC As String = "", _
                                Optional IsImportant As Boolean = False, _
                                Optional Attachment As String = "", _
                                Optional Attachment2 As String = "", _
                                Optional Attachment3 As String = "", _
                                Optional Attachment4 As String = "", _
                                Optional Attachment5 As String = "", _
                                Optional Attachment6 As String = "", _
                                Optional FormatAsHTML As Boolean = False)
                                
                                
    Dim objOutlook As Outlook.Application
    Dim objOutlookMsg As Outlook.MailItem
    Dim objOutlookRecip As Outlook.Recipient
    Dim objOutlookAttach As Outlook.Attachment
    
    ' Create the Outlook session.
    Set objOutlook = CreateObject("Outlook.Application")
    
    ' Create the message.
    Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
    
    objOutlook
    
    With objOutlookMsg
        ' Add the To recipient(s) to the message.
        If MessageTO <> "" Then
            Set objOutlookRecip = .Recipients.add(MessageTO)
            objOutlookRecip.Type = olTo
        End If
        
        ' Add the CC recipient(s) to the message.
        If MessageCC <> "" Then
            Set objOutlookRecip = .Recipients.add(MessageCC)
            objOutlookRecip.Type = olCC
        End If
        
        ' Add the BCC recipient(s) to the message.
        If MessageBCC <> "" Then
            Set objOutlookRecip = .Recipients.add(MessageBCC)
            objOutlookRecip.Type = olBCC
        End If
        
        ' Set the Subject, Body, and Importance of the message.
        .Subject = MessageSubject
        If FormatAsHTML Then
            .HTMLBody = MessageBody
        Else
            .Body = MessageBody
        End If
        
        ' Set message importance
        If IsImportant Then
            .Importance = olImportanceHigh  'High importance
        Else
            .Importance = olImportanceNormal
        End If

        ' Add attachments to the message.
        If Attachment <> "" Then
           Set objOutlookAttach = .Attachments.add(Attachment)
        End If
        If Attachment2 <> "" Then
           Set objOutlookAttach = .Attachments.add(Attachment2)
        End If
        If Attachment3 <> "" Then
           Set objOutlookAttach = .Attachments.add(Attachment3)
        End If
        If Attachment4 <> "" Then
           Set objOutlookAttach = .Attachments.add(Attachment4)
        End If
        If Attachment5 <> "" Then
           Set objOutlookAttach = .Attachments.add(Attachment5)
        End If
        If Attachment6 <> "" Then
           Set objOutlookAttach = .Attachments.add(Attachment6)
        End If
        
        ' Resolve each Recipient's name.
        For Each objOutlookRecip In .Recipients
           objOutlookRecip.Resolve
           If Not objOutlookRecip.Resolve Then
           objOutlookMsg.Display
        End If
        Next
        .Send
        
    End With
    Set objOutlookMsg = Nothing
    Set objOutlook = Nothing
    
End Sub

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/18/2026 7:06:11 AM. PLT: 1s