468,321 Members | 1,711 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,321 developers. It's quick & easy.

Creating an email with attachments from an Access Form using VB

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
1 2431
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.

Similar topics

1 post views Thread by Jeff S via AccessMonster.com | last post: by
1 post views Thread by budyerr | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by howard w | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.