Sending E-Mails? (1 Viewer)

H

Holtor

Guest
Hi All,

I have an Access Database and I'd love to be able to integrate a function to send e-mail from it. Basically I store the users email and some other info. I'd like to create a button like "Send E-Mail" and when you click it it'll take the information in the Form and send them an e-mail.

Is this even possible? TIA!!
 

Peter D

Registered User.
Local time
Today, 19:21
Joined
Sep 7, 2000
Messages
188
Sure!

Use the SendObject method:

SEND AN E-MAIL MESSAGE FROM ACCESS

You need an e-mail program that uses MAPI, like Outlook Express:

DoCmd.SendObject ,,,"ToJohn@doe.com",,,"Subject","Message",False

The above example will put an e-mail message to "ToJohn@doe.com" into your outbox. To have the e-mail send window pop up, change the last parameter to "True". To send to more addresses, separate the addresses with a semicolon. Here's another example that shows where to put CC and Bcc addresses:

DoCmd.SendObject , , , "ToJohn@doe.com;ToBill@doe.com","CcMary@doe.com" ,"BccSue@doe.com" , "Subject", "Message", False

E-MAIL THE OUTPUT OF A REPORT FROM ACCESS

Here's an example of how to send the output of a report named "Sales By Order" via e-mail. If your report prompts you for parameters, you will be prompted for them when you run this command:

DoCmd.SendObject acSendReport, "Sales By Order", acFormatRTF, "ToJohn@doe.com", , , "Subject", "Message", False

The "acFormatRTF" parameter will send the report output in a format that can be read by MS Word. You can also use:

"acFormatHTML" - Your sent report output will be opened with a web browser.
"acFormatTXT" - Your sent report output will be opened with notepad, or wordpad.

E-MAIL AN ATTACHMENT

To include an attachment with your e-mail, you need to use automation because SendObject won't do this. Here's how to use automation to send an e-mail attachment: http://support.microsoft.com/support/kb/articles/q209/9/48.asp

Hope this helps,

Peter De Baets
Peter's Software - MS Access Tools For Developers http://www.peterssoftware.com
 
H

Holtor

Guest
Peter,

I've been playing around with this and can't seem to get it working. I'm very new to all of this you see.


Where do I put this code? I have a Command Button and I tried to put it in the OnClick procedure which gave some macro error.

I tried to make a macro from it but then all it did was open a blank email message for composition in outlook express.

Any idea? Thanks again!
 

BukHix

Registered User.
Local time
Today, 14:21
Joined
Feb 21, 2002
Messages
379
Let me take Peter D's post one step further. To loop through a query or table to get the email addresses you would use this with the SendObject:

Dim rsEmail As DAO.Recordset
Dim strEmail As String
Set rsEmail = CurrentDb.OpenRecordset("YourQuery")

Do While Not rsEmail.EOF
strEmail = rsEmail.Fields("EmailAddress").Value
DoCmd.SendObject , , , strEmail, , , "Subject", "Message Text"

rsEmail.MoveNext

Loop
Set rsEmail = Nothing

Also if you want to place information from the form into the email you would replace the "message text" with me.TextBoxName (no quotes). You can so the same thing with the subject also.
 

BukHix

Registered User.
Local time
Today, 14:21
Joined
Feb 21, 2002
Messages
379
Holtor, cut and paste the code that you were putting behind the command button here so we can take a look at it.
 
H

Holtor

Guest
I've acctually figured out why it was not working. The code belonged in the Code Builder and not in the Expression builder.

However.. how would I specify the FROM: address that the email would send as? Now it uses the default Outlook Express profile but i'd like it to use something else. Any idea?
 

Peter D

Registered User.
Local time
Today, 19:21
Joined
Sep 7, 2000
Messages
188
>Where do I put this code?

In a command button OnClick event procedure (not in the OnClick property). Click the build button "..." next to the OnClick property to create an event procedure.

Hope this helps,

Peter De Baets
Peter's Software - MS Access shareware and freeware for developers http://www.peterssoftware.com
 

Users who are viewing this thread

Top Bottom