Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding an attachment to an email.

Status
Not open for further replies.

nim180

IS-IT--Management
Aug 11, 2005
161
AU
Hi Everyone,

I'm trying to email through access but I'm not sure how to make an attachment. The code to generate an email works fine but i have been requested to have the ability to add an attachment. This is my code:

Code:
Private Sub Command23_Click()
On Error Resume Next
    Dim strToWhom     As String
    Dim strMsgBody    As String
    Dim strTitle      As String
    
    
    With Me.Recordset
        .MoveFirst
        While Not .EOF
            strToWhom = strToWhom & ";" & Me!Email
            strToWhom = Mid(strToWhom, 2)
            strMsgBody = "Dear " & Me!Name & " " & Me!Text9 & "," & vbCrLf _
                         & vbCrLf _
                         & Me!emailtxt & vbCrLf _
                         & vbCrLf _
                         & "Kind Regards," & vbCrLf _
                         & "Helena" & vbCrLf _
                         & "Helena Cleaning Services" & vbCrLf _
                         & "0414272616" & vbCrLf _

            strTitle = strTitle & Me!title
            
              
         DoCmd.SendObject , , , strToWhom, , , strTitle, strMsgBody, False
            strToWhom = ""
            .MoveNext
        Wend
    End With
    
End Sub

Thanks,
Nim
 
What email client are you using, I ask this as SendObject is best used with a query or report with you database and is not email client specific

If you are using Outlook then something like this would do

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



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

With objEmail
.To = " EMAIL TO ADDRESS"
.Subject = "BLAH BLAH BLAH"
.Body = "Message text"
.Attachments.Add "C:\yourfolder\xyz.doc"
.Send
End With

objOutlook.Quit
Set objEmail = Nothing



If you want the user to browse for a file to attach the use a text box with the proximity function from here
Hope this helps


Jimmy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top