473,487 Members | 2,466 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 2843
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
3678
by: tabonni | last post by:
Hi I try to grab the checked files from HTML page and then send those PDF files as attachments. It can just send email, there are no PDF files attached. Can anybody point out my error? My...
1
1676
by: Jeff S via AccessMonster.com | last post by:
Hello, I got some code from http://www.fabalou.com/VBandVBA/lotusnotesmail.asp to send emails atomatically from access. It works but does not attach anything to the email I am trying to email...
9
3006
by: RedMoosh | last post by:
is it possible to rn a client side vbscript to send messages using cdo.message and cdo.configuration? what are the requirements to do this? my wks are xp and 2000 and all have cdosys.dll...
10
2158
by: Walshi | last post by:
Hi all, I'm a relative newby to access and VBA etc. My forms and tables etc are working great and saving lots of time...However... I have two databases with the exact same table format. I want...
1
2804
by: pixie | last post by:
Hi. Access 2003. The database stores contract information. I have a query for each person that is responsible for contracts. The query checks to see if there are reports due either this week,...
1
3944
by: rmarek | last post by:
I need to create an Outlook email from within Access that adds all the contents of a specific file folder as attachments. I have been able to get the email created and drop it into the Outlook...
1
3849
by: budyerr | last post by:
All, I am trying to build a email submission form using asp.net. I currently have a web form page that will upload to my webhosting server, attach to email then delete the file after sending. ...
4
6698
by: kpfunf | last post by:
When I email a report via macro or vba code, the attached report is named "Fuel Quote Report.(ext)". I have no idea how this name is used. I have three seperate macros sending three seperate reports....
3
1473
by: atlanteavila | last post by:
Hello all, I've got a database that is used to register couples preparing to get married in our Church to a class named Pre-Cana, we collect couples personal infomation along with email addresse,...
0
7105
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7132
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7180
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5439
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4564
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3076
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3071
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1381
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
266
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.