Access 97 - Sending an Email with Content using a Command Button

G

Guest

I have a database that is used to log details about received materials, when
a new receipt is entered, I want some of the record detail sent to a choosen
person via the users email when a button is clicked

I currently have a command button "eMail_Btn" with the following in the "On
Click" Event - Application.FollowHyperlink "mailto:" & Me.EMailAddress.Value
EMailAddress being the field on the input form to choose the email address
to send.

This works fine, but only Opens the email software and populates the To
section with the selected email address, but what I also need to do is also
populate the CC, Subject and include two or three pieces of information
within the body of the email with data also taken from fields within the
input form and automatically send the email.

I have been doing this with another system that emails to Lotus Notes from
Lotus Notes, but I now need to be able to change this to use any email
software.

I appreciate any help offered.

Joe
 
R

Rob Parker

Check out the SendObject method in the help file. It allows you to set
several parameters (including cc: and subject: fields), and send any of
several objects (query, report, table, ...) as an attachment, in various
formats.

HTH,

Rob
 
G

Guest

Rob

Thanks for you reply, I tried the following to send the table "TBL_MAIN" in
XL format to Nancy Davolio and cc to Joan Weber with the subject being "New
Data Table"

DoCmd.SendObject acSendTable, "TBL_MAIN", acFormatXLS, "Nancy Davolio",
"Joan Weber", , "New Data Table"

This has returned the run time error 2287, "Microsoft Access cannot open the
mail session"

Any suggestions would be appreciated.

Thanks

Joe
 
R

Rob Parker

Hi Joe,

The line you posted works fine for me (when I change TBL_MAIN to the name of
an actual table). I get an email message with an Excel spreadsheet
attachment (tblName.xls), and the To:, cc:, and Subject: fields as expected,
ready to be sent.

I've not come across the error message you've found, but from the
description I think Access is unable to find your email program. Are you
using Outlook or Outlook Express (I know there is no problem with either of
those), or something else? If it's something else, was the email program
open at the time?

Other than that, I'm at a loss for suggestions. If it's a problem with
another email program, I suggest you post a new question with details of
that.

HTH,

Rob
 
G

Guest

Hi Rob

Again, thanks for your reply, I am using Lotus Notes which was open at the
time, therefore Access 97 must have a problem recognising this email
software,if the code I tried works with outlook, it will probably work with
most others, I will try some more tests, such as with Hotmail etc, If I can
get it to work with most popular email software, that will have to do.

Thanks for your help with this, It was greatly appreciated.

Joe
 
D

DubboPete

Joe,

I had the same problem, and I use Novell Groupwise...

But, I think I have it cracked, and this may help you....

Try this code, and adapt the obvious insertions to fit your needs - just try
it to yourself (your email) to see if it works!

Private Sub CommandWhatever_Click()

DoCmd.SendObject actable, "TblName", "MicrosoftExcel(*.xls)",
"(e-mail address removed)", "(e-mail address removed)", "(e-mail address removed)",
"subject", "body goes here and you can add " & strfield_ofYour_choice & "to
say thankyou", False, ""

and further to that, you don't have to send a table, you can just send a
message by using this....

Private Sub CommandWhatever_Click()

DoCmd.SendObject, , , "(e-mail address removed)",
"(e-mail address removed)","(e-mail address removed)", "subject", "body goes here and you can
add " & strfield_ofYour_choice & "to say thankyou", False, ""

End Sub

.... but beware of line breaks in this reply to your enquiry - it happens...

If you want the code in one line, email me

osnabruc@[email protected]

Pete

End Sub
 
D

DubboPete

change the first part of the line to

DoCmd.SendObject acTable, ...................

(take out "send" from acSendTable to make acTable)
 
G

Guest

Thanks for your reply DubboPete

I will try your solution right away and let you know the results as soon as
I run it.

Thanks in anticipation


Joe
 
R

Rob Parker

Hi Joe,

I strongly suspect that DoCmd.SendObject will not work with Hotmail (or
gmail, or Yahoo mail), since that is not an email program per se; it (they)
are web-based mail services. It might well work with other email clients
such as Thunderbird, Eudora, Pegasus, etc.

I've never used Lotus Notes, so I can't comment on whether that might be the
source of your problem.

Rob
 
D

DubboPete

Hi Rob,

I agree with you here, but I have made this work with Novell Groupwise,
Lotus Notes, et al... and even Outlook!
All proprietary email programs...

Pete
 
G

Guest

Hi DubboPete

I have tried both options which you suggested, I am beginning to think that
Lotus Notes is not the email to have, the two options failed, below is what I
have coded and the messages returned, maybe I have made an error (not for the
first time)

As you will see, I have renamed the Private Sub to reflect My Command
Button, also the Table for a real table in my daytabase, and inserted a
string called Ref

Private Sub eMail_Btn_Click()
Dim strRef As String
strRef = Me!Rec_Ref

DoCmd.SendObject acTable, "Tbl_Procedure", "MicrosoftExcel(*.xls)",
"(e-mail address removed)", "(e-mail address removed)", "Test Subject", "Test Body
Text " & strRef & "Thanks", False, ""

This Returned the message "An expression you enterer is the wrong data type
for one of the arguments"

DoCmd.SendObject , , , "(e-mail address removed)", "(e-mail address removed)",
"(e-mail address removed)", "Test Subject", "Test Body " & strRef & "Test Thanks",
False, ""

This Returned the message "Microsoft Access cant open the Mail session"

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top