Skip to main content

CreateObject

Public Sub cmdEmailContact_Click()

    Dim appOutLook As Outlook.Application
    Dim MailOutLook As Outlook.MailItem
    Dim strPath As String
    Dim strFilter As String
    Dim strFile As String
    Dim strFileEnd  As String
    Dim strEmailRecipients As String

    strPath = "C:UsersusernameDesktopInvoice TestGCX"
    strFilter = Me.txtInvNum
    strFileEnd = ".pdf"
    strFile = Dir(strPath & strFilter & strFileEnd)
    strEmailRecipients = ""
      For N = 0 To Me.lstContacts.ListCount - 1
         If Me.lstContacts.Selected(N) = True Then
            strEmailRecipients = strEmailRecipients & "; " & Me.lstContacts.Column(3, N)  
         End If
      Next N
    strEmailRecipients = Mid(strEmailRecipients, 3)

    If strFile <> "" Then

        Set appOutLook = CreateObject("Outlook.Application")
        Set MailOutLook = appOutLook.CreateItem(olMailItem)

        With MailOutLook
            .BodyFormat = olFormatRichText
            .To = strEmailRecipients
            ''.cc = ""
            ''.bcc = ""
            .Subject = "text here"
            .SentOnBehalfOfName = "gcacash@uw.edu"
            .HTMLBody = "text here"
            .Attachments.Add (strPath & strFilter & strFileEnd)
            '.Send
            .Display
        End With
    Else
        MsgBox "No file matching " & strPath & strFilter & strFileEnd & " found." & vbCrLf & _
                "Process has been stopped."
        Exit Sub  
    End If

End Sub