Attach Multiple items to outlook email (1 Viewer)

MooTube

Registered User.
Local time
Today, 08:29
Joined
Jul 2, 2015
Messages
31
Hello,

I am currently in the process of creating a form that will allow you to enter details for an email sent, select a number of documents from a list box and then open the mail message pre-written with attachments. The attachments reside in a list box currently, and I am attempting to use a "For Each" with item selected.column(3) as the file path, as column(3) contains the filepath from the table.

Currently my code is:

Code:
Private Sub OutlookBut_Click()

Dim olApp As Object
Dim objMail As Object
Dim varItm As Variant

On Error Resume Next

    Set olApp = GetObject(, "Outlook.Application")

If Err Then
    Set olApp = CreateObject("Outlook.Application")
End If

Set objMail = olApp.CreateItem(olMailItem)

With objMail
    .To = Me.Email
    .Subject = Me.Subject
    .CC = Me.CC
    .BCC = Me.BCC
For Each varItm In Me.AttachBox.ItemsSelected
    .Attachments = Me.AttachBox.Column(3)
Next varItm
End With

End Sub

When this code runs, outlook will open as a process when it is closed, but then freeze and not allow me to see it or access it in anyway. If Outlook is opened Microsoft office usually gets angry at me and decides to throw error messages at me.

I was wondering if anyone could help out with this code, as my project is nearly finished and it would be a huge relief!

Thanks
 

Ranman256

Well-known member
Local time
Today, 11:29
Joined
Apr 9, 2015
Messages
4,339
For Each varItm In AttachBox.ItemsSelected
.Attachments.Add AttachBox.Column(3), olByValue, 1
Next
 

MooTube

Registered User.
Local time
Today, 08:29
Joined
Jul 2, 2015
Messages
31
I was able to get this working

Code:
Dim strEmail As String
Dim strMsg As String
Dim oLook As Object
Dim oMail As Object
Dim oNS As Object
Dim Email As String
Dim CC As String
Dim BCC As String
Dim Subject As String
Dim Attach As String



Set oLook = CreateObject("Outlook.Application")
Set oMail = oLook.createitem(0)


If IsNull(Me.Email) Then
GoTo noemail
Else
Email = Me.Email
End If


CC = Me.CC
BCC = Me.BCC
Subject = Me.Subject
Attach = Application.CurrentProject.path + "\" + Me.AttachBox.Column(3, i)
Body = "Dear " & Me.Title & " " & Me.LName & "," & vbNewLine & vbNewLine & "I have been instructed to forward the attached documents regarding current information on the company for your perusal." & vbNewLine & vbNewLine & "Kind regards" & vbNewLine & vbNewLine & vbNewLine & "The MCB Team"



With oMail
    .To = Email
    .CC = CC
    .BCC = BCC
    .Subject = Subject
    .Body = Body
     Msg = "Attached:" & vbNewLine
    For i = 0 To Me.AttachBox.ListCount - 1
        If Me.AttachBox.Selected(i) Then
 
            .Attachments.Add Application.CurrentProject.path + Me.AttachBox.Column(3, i)
            Msg = Msg & Me.AttachBox.Column(1, i) & vbNewLine
        End If
     Next i
    .Display
End With
     
    MsgBox Msg
    MsgBox "Please Update Documents Sent"
    

DoCmd.Close , "SendEmailForm", acSaveYes



Exit Sub

noemail:
    MsgBox "This person has no email, please enter an email", vbOKOnly, "No Email"
Exit Sub
 

Users who are viewing this thread

Top Bottom