Question : Email Attachments

Hi Experts,

I need to be able to send a file (not an Access Object) as an email attachment from VBA code:

DoCmd.SendObject acSendNoObject, "C:\File.txt", , strEmailAddress, , , srtSubject, strMsgText, True
(doesn't work because it's expecting the name of an Access Object)

Is there another way?

Thanks!

Doug

Answer : Email Attachments

You can use something like this

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
Sub SendReports(DisplayMsg As Boolean)
    Dim objOutlook As Object
    Dim objOutlookMsg As Object
    Dim strTo as String
    Dim strSubject as String
    Dim strBody as String
    Dim strAttach as String
    
    ' Create the Outlook session.
    Set objOutlook = CreateObject("Outlook.Application")
    
    ' Create the message.
    Set objOutlookMsg = objOutlook.CreateItem(0)
 
    strTo = "xxxx"
    strSubject = "yyyy"
    strBody = "XXXX"
    strAttach = path & filename
    
    With objOutlookMsg
        .To = strTo
        Subject = strSubject
        .Body = strBody
        .Attachments.Add strAttach
        .Save
        .Open
    End With
    Set objOutlook = Nothing
End Sub
Open in New Window Select All
Random Solutions  
 
programming4us programming4us