By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,890 Members | 1,226 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,890 IT Pros & Developers. It's quick & easy.

Creating an email with attachments from an Access Form using VB

P: n/a
If someone could help me, I need to be able to send attachments from my
access database that I have created. This database runs queries then
generates a report off the queries from underlying tables and emails
the reports as HTML format in the body, I then need to have this same
process go out to my C:\ drive and pick up a couple files and add it to
the same email as attachments. If someone could please give me a
sample code that would work, please as simple as it could be would be
best because I know very little with VB. Thanks

May 5 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
I have been using the following function. I hope it helps

'---------------------
' Create a email with attachments
' stSendTo Email address
' stBody Body of the message
' stSubject Subject of the message
' astAttach Array of strings listing the path to the attachments
' intAcount Number of attachments
' intSend True if the message should be sent without preview

Public Function emailAttach(ByRef stSendTo As String, ByRef stBody As
String, _
ByRef stSubject As String,
astAttach() As String, _
intAcount As Integer, intSend As
Integer) As Integer

On Error GoTo erremailAttach

Dim oLook As Object
Dim oMail As Object
Dim i As Integer

Set oLook = CreateObject("Outlook.Application")
Set oMail = oLook.CreateItem(0)
With oMail
.To = stSendTo
.Body = stBody
.Subject = stSubject

' The following line asks the addressee to reply on opening the
email.
.ReadReceiptRequested = True

If intAcount <> 0 Then
For i = 1 To intAcount
.Attachments.Add (astAttach(i - 1))
Next
End If

If intSend = True Then
.Send
Else
.Display
End If

End With

Set oMail = Nothing
Set oLook = Nothing
emailAttach = True
Exit Function

erremailAttach:

MsgBox "The following error was noted : " & Err.Description & Chr$(10) &
Chr$(13) & _
"Your email may not have been sent.", vbCritical, "Error"

On Error Resume Next
Set oMail = Nothing
Set oLook = Nothing
emailAttach = False

End Function

"mike11d11" <mi*******@yahoo.com> wrote in message
news:11**********************@g10g2000cwb.googlegr oups.com...
If someone could help me, I need to be able to send attachments from my
access database that I have created. This database runs queries then
generates a report off the queries from underlying tables and emails
the reports as HTML format in the body, I then need to have this same
process go out to my C:\ drive and pick up a couple files and add it to
the same email as attachments. If someone could please give me a
sample code that would work, please as simple as it could be would be
best because I know very little with VB. Thanks

May 5 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.