Add more than one Attachment

Lochwood

Registered User.
Local time
Today, 12:47
Joined
Jun 7, 2017
Messages
130
Ok i have button that can send an attachment via email.. it launches outlook if its not open, creates an instance and attaches a file based on the populated hyperlink field in the record.. GREAT! What i want to do is then goto another record, press the button and it adds the second attachment based on that hyperlink field. currently when i do this, it adds another instance and does not attach it to the same email. how can i achieve this to say only open new item if item is not already open. here is my code.

Dim olApp As Object
Dim objMail As Object
Dim strPath As String

strPath = Me.Hyperlink 'Edit to your path

On Error Resume Next
Set olApp = GetObject(, "Outlook.Application") 'See if Outlook is open

If Err Then 'Outlook is not open
Set olApp = CreateObject("Outlook.Application") 'Create a new instance
End If


Set objMail = olApp.CreateItem(olMailItem)

With objMail
.BodyFormat = olFormatHTML
.To = ""
.Subject = ""
.HTMLBody = ""
.Attachments.Add (strPath)
.Send
.Display
End With


End Sub
 
this allows user to pick many files and puts them into a collection,
attach all files to the email from the collection.

Code:
sub SendEmailFiles()
dim colFiles as collection
dim vFile

set colFiles = UserPickFiles()

'email setup.....

'send
With objMail
  .BodyFormat = olFormatHTML
  .To = "bob@myplace.com"
  .Subject = "my subj"
  .HTMLBody = "does a body good"
  
    for each vFile in colFiles
      .Attachments.Add (vFile)
    next

  .Send
  '.Display
End With
set colFiles =nothing
end sub


Public Function UserPickFiles() As Collection
Dim strTable As String
Dim strFilePath As String
Dim sDialog As String, sDecr  As String, sExt As String
Dim fD As FileDialog
Dim vFile
Dim colFiles As New Collection

Set fD = Application.FileDialog(msoFileDialogFilePicker)   '<----!!  MUST ADD REFERENCE : Microsoft Office 11.0 Object Library
With fD
    .AllowMultiSelect = True
    .Title = "Locate a file to Import"
    .ButtonName = "Import"
    .Filters.Clear
    .Filters.Add "All Files", "*.*"
    .InitialFileName = "c:\"
    .InitialView = msoFileDialogViewList    'msoFileDialogViewThumbnail
    .AllowMultiSelect = True
     
        If .show = 0 Then
           'There is a problem
           Exit Function
        End If
    
            'collect the picked files
        For Each vFile In .SelectedItems
           colFiles.Add vFile
        Next
      
      'RETURN THE FILES PICKED
    Set UserPickFiles = colFiles
End With
Set fD = Nothing
End Function
 
This wont work for me.. really need it to be for each record the user chooses. every record has a different hyperlink path so it gets the file from that location and adds it to the existing email.
 
Does the hyperlink contain the full path to the file to be attached? If so could you write a query that collects the items to be included, then you could create a recordset to loop through the hyperlinks to pull the attachments. Another option, if the criteria are more random is to use a multi-select list box and loop through those selected items.
 

Users who are viewing this thread

Back
Top Bottom