How to attach attachments?

  • Thread starter Thread starter Billy Banter
  • Start date Start date
B

Billy Banter

Hello All,

I have the following code from the emailsenate database and I am trying to
find out how to also attach an attachment.

Private Sub cmdEmail_Click()
On Error GoTo Err_cmdEmail_Click

Dim strDocName As String
Dim strEmail As String
Dim strMailSubject As String
Dim strMsg As String

strDocName = Me.lstRpt
strEmail = Me.txtSelected & vbNullString
strMailSubject = Me.txtMailSubject & vbNullString
strMsg = Me.txtMsg & vbNullString & vbCrLf & vbCrLf & "Your Name" & _
vbCrLf & "MailTo:[email protected]"

DoCmd.SendObject objecttype:=acSendReport, _
ObjectName:=strDocName, outputformat:=acFormatHTML, _
To:=strEmail, Subject:=strMailSubject, MessageText:=strMsg

Exit_cmdEmail_Click:
Exit Sub

Err_cmdEmail_Click:
MsgBox Err.Description
Resume Exit_cmdEmail_Click

End Sub

I also have this code as well which will attach an attachment but it doesn't
open up a new email. It just sends it off. I guess some kind of mix of both
of them.

Private Sub Command2_Click()

'Arvin Meyer 03/12/1999
'Updated 7/21/2001
On Error GoTo Error_Handler

Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem

Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)

With objEmail
.To = "(e-mail address removed)"
.Subject = "Look at this sample attachment"
.Body = "The body doesn't matter, just the attachment"
.Attachments.Add "C:\Documents and Settings\Administrator\My
Documents\hh.CSV"
'.attachments.Add "c:\Path\to\the\next\file.txt"
.Send
'.ReadReceiptRequested
End With

Exit_Here:
Set objOutlook = Nothing
Exit Sub

Error_Handler:
MsgBox Err & ": " & Err.Description
Resume Exit_Here

End Sub

regards

Billy
 
How would you send multiple attachments. eg 1.jpg 2.jpg and so on
 
Not something I've done but if you are hard coding the document paths could
you not repeat the line
Attachments.Add "C:\Documents and Settings\Administrator\My
Documents\hh.CSV"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top