code for sending an email 
Author Message
 code for sending an email

Hi,

I've added some code into my database that sends a multi-
purpose email: it attaches an object (a report), and fills
in the recipient, subject, and text of the Outlook email
message. All of these parts include variables from the
form that's open (which contains the command button that
generates the email).
The problem is: sometime it works, and sometime is
doesn't. Sometimes I get messages like "Reserved error"
or "Send object was cancelled". I know that Access 2000
has problem generating emails like this when the messages
contain too many characters, but my message doesn't
contain 98 (the knowledge base article says problems begin
with 98+ characters). Do I need to install some extra
feature or something? What is most likely the problem?

Any help is greatly appreciated! monica

By the way, here's (basically) the code I have in
the "OnClick" event procedure:

Private Sub Mail _Report_Click()
On Error GoTo Err_Mail_Report_Click

    Dim stDocName As Variant, SendToRecipient As Variant
    Dim PackageSubject As Variant, PackageMessage As String

    SendToRecipient = DLookup
("[email]", "tblReviewers", "[Name]=Forms!
[frmIncomingPackage]![Route To]")
    NewPackSubject = DLookup("[Project
Number]", "tblIncomingPackages", "[Incoming Package]=Forms!
[frmIncomingPackage]![Incoming Package]") & _
        " Section" & DLookup
("[Section]", "tblIncomingPackages", "[Incoming Package]
=Forms![frmIncomingPackage]![Incoming Package]")
    NewPackMessage = "Please review the attached items."
    stDocName = "Report"
    DoCmd.SendObject acReport, stDocName, ,
SendToRecipient, , , PackageSubject, PackageMessage, , True

Exit_Mail_Pink_Slip_Click:
    Exit Sub

Err_Mail_Pink_Slip_Click:
    MsgBox Err.Description
    Resume Exit_Mail_Pink_Slip_Click

End Sub



Sat, 17 Jul 2004 10:02:55 GMT  
 code for sending an email
Here is one way to do it using the Outlook object model.
You need to set a reference to Outlook for it to work.

Sub SendEmailMessage(strSubject As String, strBody As String, strTo As
String)
On Error GoTo Err_SendEmailMessage
  Dim ol As New Outlook.Application
  Dim ns As Outlook.NameSpace
  Dim newMail As Outlook.MailItem

  Set ns = ol.GetNamespace("MAPI")
  Set newMail = ol.CreateItem(olMailItem)
  With newMail
    .Subject = strSubject
    .Body = strBody & vbCRLF
    With .Recipients.Add(strTo)
      .Type = olTo
    End With
    .Send
  End With

Exit_SendEmailMessage:
  Set ol = Nothing
  Set ns = Nothing
  Set newMail = Nothing
  Exit Sub

Err_SendEmailMessage:
  MsgBox ("Error # " & str(Err.Number) & " was generated by " & Err.Source &
Chr(13) & Err.Description)
  Resume Exit_SendEmailMessage

End Sub
--
Joe Fallon
Access MVP


Quote:
> Hi,

> I've added some code into my database that sends a multi-
> purpose email: it attaches an object (a report), and fills
> in the recipient, subject, and text of the Outlook email
> message. All of these parts include variables from the
> form that's open (which contains the command button that
> generates the email).
> The problem is: sometime it works, and sometime is
> doesn't. Sometimes I get messages like "Reserved error"
> or "Send object was cancelled". I know that Access 2000
> has problem generating emails like this when the messages
> contain too many characters, but my message doesn't
> contain 98 (the knowledge base article says problems begin
> with 98+ characters). Do I need to install some extra
> feature or something? What is most likely the problem?

> Any help is greatly appreciated! monica

> By the way, here's (basically) the code I have in
> the "OnClick" event procedure:

> Private Sub Mail _Report_Click()
> On Error GoTo Err_Mail_Report_Click

>     Dim stDocName As Variant, SendToRecipient As Variant
>     Dim PackageSubject As Variant, PackageMessage As String

>     SendToRecipient = DLookup
> ("[email]", "tblReviewers", "[Name]=Forms!
> [frmIncomingPackage]![Route To]")
>     NewPackSubject = DLookup("[Project
> Number]", "tblIncomingPackages", "[Incoming Package]=Forms!
> [frmIncomingPackage]![Incoming Package]") & _
>         " Section" & DLookup
> ("[Section]", "tblIncomingPackages", "[Incoming Package]
> =Forms![frmIncomingPackage]![Incoming Package]")
>     NewPackMessage = "Please review the attached items."
>     stDocName = "Report"
>     DoCmd.SendObject acReport, stDocName, ,
> SendToRecipient, , , PackageSubject, PackageMessage, , True

> Exit_Mail_Pink_Slip_Click:
>     Exit Sub

> Err_Mail_Pink_Slip_Click:
>     MsgBox Err.Description
>     Resume Exit_Mail_Pink_Slip_Click

> End Sub



Sat, 17 Jul 2004 12:09:31 GMT  
 code for sending an email
Monica, I seem to have experienced the same problem. Have you resolved it? I
am getting the 2501 Send Object was canceled error. Like yours, my is
related to sending a report. I wonder if that is the problem. Sending via a
report causes a problem?

Scott


Quote:
> Hi,

> I've added some code into my database that sends a multi-
> purpose email: it attaches an object (a report), and fills
> in the recipient, subject, and text of the Outlook email
> message. All of these parts include variables from the
> form that's open (which contains the command button that
> generates the email).
> The problem is: sometime it works, and sometime is
> doesn't. Sometimes I get messages like "Reserved error"
> or "Send object was cancelled". I know that Access 2000
> has problem generating emails like this when the messages
> contain too many characters, but my message doesn't
> contain 98 (the knowledge base article says problems begin
> with 98+ characters). Do I need to install some extra
> feature or something? What is most likely the problem?

> Any help is greatly appreciated! monica

> By the way, here's (basically) the code I have in
> the "OnClick" event procedure:

> Private Sub Mail _Report_Click()
> On Error GoTo Err_Mail_Report_Click

>     Dim stDocName As Variant, SendToRecipient As Variant
>     Dim PackageSubject As Variant, PackageMessage As String

>     SendToRecipient = DLookup
> ("[email]", "tblReviewers", "[Name]=Forms!
> [frmIncomingPackage]![Route To]")
>     NewPackSubject = DLookup("[Project
> Number]", "tblIncomingPackages", "[Incoming Package]=Forms!
> [frmIncomingPackage]![Incoming Package]") & _
>         " Section" & DLookup
> ("[Section]", "tblIncomingPackages", "[Incoming Package]
> =Forms![frmIncomingPackage]![Incoming Package]")
>     NewPackMessage = "Please review the attached items."
>     stDocName = "Report"
>     DoCmd.SendObject acReport, stDocName, ,
> SendToRecipient, , , PackageSubject, PackageMessage, , True

> Exit_Mail_Pink_Slip_Click:
>     Exit Sub

> Err_Mail_Pink_Slip_Click:
>     MsgBox Err.Description
>     Resume Exit_Mail_Pink_Slip_Click

> End Sub



Sun, 18 Jul 2004 00:11:50 GMT  
 code for sending an email
Monica, someone answered this in another newsgroup with:

ACC2000: SendObject Method Fails in Access 2000 (Q260819)
http://support.microsoft.com/default.aspx?scid=kb;en-us;q260819

I think this may be the problem. Especially when sending more than once
inside a routine.

Scott


Quote:
> Monica, I seem to have experienced the same problem. Have you resolved it?
I
> am getting the 2501 Send Object was canceled error. Like yours, my is
> related to sending a report. I wonder if that is the problem. Sending via
a
> report causes a problem?

> Scott



> > Hi,

> > I've added some code into my database that sends a multi-
> > purpose email: it attaches an object (a report), and fills
> > in the recipient, subject, and text of the Outlook email
> > message. All of these parts include variables from the
> > form that's open (which contains the command button that
> > generates the email).
> > The problem is: sometime it works, and sometime is
> > doesn't. Sometimes I get messages like "Reserved error"
> > or "Send object was cancelled". I know that Access 2000
> > has problem generating emails like this when the messages
> > contain too many characters, but my message doesn't
> > contain 98 (the knowledge base article says problems begin
> > with 98+ characters). Do I need to install some extra
> > feature or something? What is most likely the problem?

> > Any help is greatly appreciated! monica

> > By the way, here's (basically) the code I have in
> > the "OnClick" event procedure:

> > Private Sub Mail _Report_Click()
> > On Error GoTo Err_Mail_Report_Click

> >     Dim stDocName As Variant, SendToRecipient As Variant
> >     Dim PackageSubject As Variant, PackageMessage As String

> >     SendToRecipient = DLookup
> > ("[email]", "tblReviewers", "[Name]=Forms!
> > [frmIncomingPackage]![Route To]")
> >     NewPackSubject = DLookup("[Project
> > Number]", "tblIncomingPackages", "[Incoming Package]=Forms!
> > [frmIncomingPackage]![Incoming Package]") & _
> >         " Section" & DLookup
> > ("[Section]", "tblIncomingPackages", "[Incoming Package]
> > =Forms![frmIncomingPackage]![Incoming Package]")
> >     NewPackMessage = "Please review the attached items."
> >     stDocName = "Report"
> >     DoCmd.SendObject acReport, stDocName, ,
> > SendToRecipient, , , PackageSubject, PackageMessage, , True

> > Exit_Mail_Pink_Slip_Click:
> >     Exit Sub

> > Err_Mail_Pink_Slip_Click:
> >     MsgBox Err.Description
> >     Resume Exit_Mail_Pink_Slip_Click

> > End Sub



Sun, 18 Jul 2004 02:57:25 GMT  
 code for sending an email
I would suggest using the article Q260819 stated below and
add a class module in your project with the code supplied
at the end of the article. Using this, you'll be able to
run the DoCmd.SendObject more than once and also won't be
limited the the number of characters in the message body.

You can also use the link below for another code sample:

http://support.microsoft.com/default.aspx?scid=kb;en-
us;Q161088

Please note that you will need to create a file first on
the HDD before you can attach it in the last code.

Dominic

Quote:
>-----Original Message-----
>Monica, someone answered this in another newsgroup with:

>ACC2000: SendObject Method Fails in Access 2000 (Q260819)
>http://support.microsoft.com/default.aspx?scid=kb;en-
us;q260819

>I think this may be the problem. Especially when sending
more than once
>inside a routine.

>Scott


message

>> Monica, I seem to have experienced the same problem.

Have you resolved it?
Quote:
>I
>> am getting the 2501 Send Object was canceled error.
Like yours, my is
>> related to sending a report. I wonder if that is the

problem. Sending via

- Show quoted text -

Quote:
>a
>> report causes a problem?

>> Scott



>> > Hi,

>> > I've added some code into my database that sends a
multi-
>> > purpose email: it attaches an object (a report), and
fills
>> > in the recipient, subject, and text of the Outlook
email
>> > message. All of these parts include variables from the
>> > form that's open (which contains the command button
that
>> > generates the email).
>> > The problem is: sometime it works, and sometime is
>> > doesn't. Sometimes I get messages like "Reserved
error"
>> > or "Send object was cancelled". I know that Access
2000
>> > has problem generating emails like this when the
messages
>> > contain too many characters, but my message doesn't
>> > contain 98 (the knowledge base article says problems
begin
>> > with 98+ characters). Do I need to install some extra
>> > feature or something? What is most likely the problem?

>> > Any help is greatly appreciated! monica

>> > By the way, here's (basically) the code I have in
>> > the "OnClick" event procedure:

>> > Private Sub Mail _Report_Click()
>> > On Error GoTo Err_Mail_Report_Click

>> >     Dim stDocName As Variant, SendToRecipient As
Variant
>> >     Dim PackageSubject As Variant, PackageMessage As
String

>> >     SendToRecipient = DLookup
>> > ("[email]", "tblReviewers", "[Name]=Forms!
>> > [frmIncomingPackage]![Route To]")
>> >     NewPackSubject = DLookup("[Project
>> > Number]", "tblIncomingPackages", "[Incoming Package]
=Forms!
>> > [frmIncomingPackage]![Incoming Package]") & _
>> >         " Section" & DLookup
>> > ("[Section]", "tblIncomingPackages", "[Incoming
Package]
>> > =Forms![frmIncomingPackage]![Incoming Package]")
>> >     NewPackMessage = "Please review the attached
items."
>> >     stDocName = "Report"
>> >     DoCmd.SendObject acReport, stDocName, ,
>> > SendToRecipient, , , PackageSubject,

PackageMessage, , True

- Show quoted text -

Quote:

>> > Exit_Mail_Pink_Slip_Click:
>> >     Exit Sub

>> > Err_Mail_Pink_Slip_Click:
>> >     MsgBox Err.Description
>> >     Resume Exit_Mail_Pink_Slip_Click

>> > End Sub

>.



Mon, 19 Jul 2004 00:27:31 GMT  
 code for sending an email
I am avoiding Outlook as to its security restrictions. If I am trying to
automate a process in Access it does me no good to have Outlook stopping the
process to confirm sending a message. Believe me I've thought long and hard
on using Outlook, but this security patch mucks up everything.

Scott


Quote:
> I would suggest using the article Q260819 stated below and
> add a class module in your project with the code supplied
> at the end of the article. Using this, you'll be able to
> run the DoCmd.SendObject more than once and also won't be
> limited the the number of characters in the message body.

> You can also use the link below for another code sample:

> http://support.microsoft.com/default.aspx?scid=kb;en-
> us;Q161088

> Please note that you will need to create a file first on
> the HDD before you can attach it in the last code.

> Dominic

> >-----Original Message-----
> >Monica, someone answered this in another newsgroup with:

> >ACC2000: SendObject Method Fails in Access 2000 (Q260819)
> >http://support.microsoft.com/default.aspx?scid=kb;en-
> us;q260819

> >I think this may be the problem. Especially when sending
> more than once
> >inside a routine.

> >Scott


> message

> >> Monica, I seem to have experienced the same problem.
> Have you resolved it?
> >I
> >> am getting the 2501 Send Object was canceled error.
> Like yours, my is
> >> related to sending a report. I wonder if that is the
> problem. Sending via
> >a
> >> report causes a problem?

> >> Scott



> >> > Hi,

> >> > I've added some code into my database that sends a
> multi-
> >> > purpose email: it attaches an object (a report), and
> fills
> >> > in the recipient, subject, and text of the Outlook
> email
> >> > message. All of these parts include variables from the
> >> > form that's open (which contains the command button
> that
> >> > generates the email).
> >> > The problem is: sometime it works, and sometime is
> >> > doesn't. Sometimes I get messages like "Reserved
> error"
> >> > or "Send object was cancelled". I know that Access
> 2000
> >> > has problem generating emails like this when the
> messages
> >> > contain too many characters, but my message doesn't
> >> > contain 98 (the knowledge base article says problems
> begin
> >> > with 98+ characters). Do I need to install some extra
> >> > feature or something? What is most likely the problem?

> >> > Any help is greatly appreciated! monica

> >> > By the way, here's (basically) the code I have in
> >> > the "OnClick" event procedure:

> >> > Private Sub Mail _Report_Click()
> >> > On Error GoTo Err_Mail_Report_Click

> >> >     Dim stDocName As Variant, SendToRecipient As
> Variant
> >> >     Dim PackageSubject As Variant, PackageMessage As
> String

> >> >     SendToRecipient = DLookup
> >> > ("[email]", "tblReviewers", "[Name]=Forms!
> >> > [frmIncomingPackage]![Route To]")
> >> >     NewPackSubject = DLookup("[Project
> >> > Number]", "tblIncomingPackages", "[Incoming Package]
> =Forms!
> >> > [frmIncomingPackage]![Incoming Package]") & _
> >> >         " Section" & DLookup
> >> > ("[Section]", "tblIncomingPackages", "[Incoming
> Package]
> >> > =Forms![frmIncomingPackage]![Incoming Package]")
> >> >     NewPackMessage = "Please review the attached
> items."
> >> >     stDocName = "Report"
> >> >     DoCmd.SendObject acReport, stDocName, ,
> >> > SendToRecipient, , , PackageSubject,
> PackageMessage, , True

> >> > Exit_Mail_Pink_Slip_Click:
> >> >     Exit Sub

> >> > Err_Mail_Pink_Slip_Click:
> >> >     MsgBox Err.Description
> >> >     Resume Exit_Mail_Pink_Slip_Click

> >> > End Sub

> >.



Mon, 19 Jul 2004 01:02:02 GMT  
 code for sending an email
I'm using automation with Outlook and it works fine BUT it
needs to be Outlook 2000 sp1 and before since sp2 ruins it
all because of the patch. If you use sp1 with your code,
it will never popup and ask to confirm.

I'm hoping you will find a good solution.

Dominic

Quote:
>-----Original Message-----
>I am avoiding Outlook as to its security restrictions. If
I am trying to
>automate a process in Access it does me no good to have

Outlook stopping the
Quote:
>process to confirm sending a message. Believe me I've

thought long and hard
Quote:
>on using Outlook, but this security patch mucks up
everything.

>Scott



>> I would suggest using the article Q260819 stated below
and
>> add a class module in your project with the code
supplied
>> at the end of the article. Using this, you'll be able to
>> run the DoCmd.SendObject more than once and also won't
be
>> limited the the number of characters in the message
body.

>> You can also use the link below for another code sample:

>> http://support.microsoft.com/default.aspx?scid=kb;en-
>> us;Q161088

>> Please note that you will need to create a file first on
>> the HDD before you can attach it in the last code.

>> Dominic

>> >-----Original Message-----
>> >Monica, someone answered this in another newsgroup
with:

>> >ACC2000: SendObject Method Fails in Access 2000
(Q260819)
>> >http://support.microsoft.com/default.aspx?scid=kb;en-
>> us;q260819

>> >I think this may be the problem. Especially when
sending
>> more than once
>> >inside a routine.

>> >Scott


>> message

>> >> Monica, I seem to have experienced the same problem.
>> Have you resolved it?
>> >I
>> >> am getting the 2501 Send Object was canceled error.
>> Like yours, my is
>> >> related to sending a report. I wonder if that is the
>> problem. Sending via
>> >a
>> >> report causes a problem?

>> >> Scott



>> >> > Hi,

>> >> > I've added some code into my database that sends a
>> multi-
>> >> > purpose email: it attaches an object (a report),
and
>> fills
>> >> > in the recipient, subject, and text of the Outlook
>> email
>> >> > message. All of these parts include variables from
the
>> >> > form that's open (which contains the command button
>> that
>> >> > generates the email).
>> >> > The problem is: sometime it works, and sometime is
>> >> > doesn't. Sometimes I get messages like "Reserved
>> error"
>> >> > or "Send object was cancelled". I know that Access
>> 2000
>> >> > has problem generating emails like this when the
>> messages
>> >> > contain too many characters, but my message doesn't
>> >> > contain 98 (the knowledge base article says
problems
>> begin
>> >> > with 98+ characters). Do I need to install some
extra
>> >> > feature or something? What is most likely the
problem?

>> >> > Any help is greatly appreciated! monica

>> >> > By the way, here's (basically) the code I have in
>> >> > the "OnClick" event procedure:

>> >> > Private Sub Mail _Report_Click()
>> >> > On Error GoTo Err_Mail_Report_Click

>> >> >     Dim stDocName As Variant, SendToRecipient As
>> Variant
>> >> >     Dim PackageSubject As Variant, PackageMessage
As
>> String

>> >> >     SendToRecipient = DLookup
>> >> > ("[email]", "tblReviewers", "[Name]=Forms!
>> >> > [frmIncomingPackage]![Rout{ w f ,)!L$?`D ?
m e To]")
>> >> >     NewPackSubject = DLookup("[Project
>> >> > Number]", "tblIncomingPackages", "[Incoming
Package]
>> =Forms!
>> >> > [frmIncomingPackage]![Incoming Package]") & _
>> >> >         " Section" & DLookup
>> >> > ("[Section]", "tblIncomingPackages", "[Incoming
>> Package]
>> >> > =Forms![frmIncomingPackage]![Incoming Package]")
>> >> >     NewPackMessage = "Please review the attached
>> items."
>> >> >     stDocName = "Report"
>> >> >     DoCmd.SendObject acReport, stDocName, ,
>> >> > SendToRecipient, , , PackageSubject,
>> PackageMessage, , True

>> >> > Exit_Mail_Pink_Slip_Click:
>> >> >     Exit Sub

>> >> > Err_Mail_Pink_Slip_Click:
>> >> >     MsgBox Err.Description
>> >> >     Resume Exit_Mail_Pink_Slip_Click

>> >> > End Sub

>> >.

>.



Mon, 19 Jul 2004 02:31:57 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. VBA code to send an email message through Lotus Notes mail interface

2. Need macro or VB code to send multiple emails

3. Need some code to send an email with the Microsoft Internet Controls

4. Send details of sender being read by vb code on send of email.

5. How to start VBA-Code when sending an email.

6. Insert details of sender into Subject line with VB code on send of email item.

7. Need to code sending email to various recipients

8. Message to SteveT re Send Email code

9. Sending Email using code

10. VBX OCX or any else piece of code send email using SMTP

11. Send/Receive email using MAPI code needed...

12. How to send an email with VBScript code?

 

 
Powered by phpBB® Forum Software