Problems with SendObject

L

Larry06Green

I created a form for users to add project records into the database. After
entering all pertinent information the user hits a command buttom that
displays a msgbox which states that their project information has been saved
and asks the user if they would like to send an email notification. The
problem I'm hearing from many of my users is that when they choose to send an
email notification, using Lotus Notes, the email does not contain a
description of their project, but instead contains the description for
someone else's project. How can I stop this from happening? Is there a remedy
for this problem? Help!!!!! Here is the VBA code behind the "Add Project"
command button:

Private Sub AddProject_Click()
On Error GoTo Err_AddProject_Click

Dim intPress As Integer
Dim intPress1 As Integer

DoCmd.Beep
intPress = MsgBox("The project information entered has been saved. Would
you like to send an Email Notification?", vbQuestion + _
vbYesNo, "Marketing Analytical Request System")

If intPress = 6 Then
DoCmd.Close
DoCmd.OpenForm "Switchboard"
DoCmd.Close
DoCmd.SendObject acSendReport, "rptLastProject", "HTML(*.html)", ,
, , "New Project Notification"
DoCmd.OpenForm "frmtest3a", acNormal
DoCmd.Maximize
DoCmd.GoToRecord , , acNewRec
End If

If intPress = 7 Then
DoCmd.Beep
intPress1 = MsgBox("Do you want to enter another Project?",
vbQuestion + _
vbYesNo, "Marketing Analytical Request System")
End If

If intPress1 = 6 Then
DoCmd.Close
DoCmd.OpenForm "Switchboard"
DoCmd.Close
DoCmd.OpenForm "frmtest3a", acNormal
DoCmd.Maximize
DoCmd.GoToRecord , , acNewRec
End If

If intPress1 = 7 Then
DoCmd.Close
DoCmd.OpenForm "Switchboard", acNormal
End If


Exit_AddProject_Click:
Exit Sub

Err_AddProject_Click:
MsgBox Err.Description
Resume Exit_AddProject_Click
End Sub
 
E

EAB1977

We use Lotus Notes for email distribution my my place of work I have
found that the SendMail isn't very cooporative with Notes. Use this
code for your send mail action:

Sub SendEmail()
Dim session As Object
Dim db As Object
Dim doc As Object
Dim rtitem As Object

Set session = CreateObject("Notes.NotesSession")
Set db = session.CurrentDatabase
Set doc = db.CreateDocument
doc.Form = "Memo"
doc.SendTo = ""
doc.Subject = "Here's the document you wanted"
doc.Body = "Here it is"
'If you need to send a attachment, uncomment and use
'Set rtitem = doc.CreateRichTextItem("Attachment")
'Call rtitem.EMBEDOBJECT(1454, "", "C:\Test.doc")
'Call rtitem.ADDNEWLINE(1, True)
Call doc.Send(False)
End Sub

You may want to point to where your HTML file is on your hard drive or
network. It'll work better that way.
 
L

Larry06Green

I tried adding your suggested code (see below) but I keep getting a compile
error. Can someone tell me what I'm doing wrong? Thanks

Private Sub Add_Project_Click()
On Error GoTo Err_Add_Project_Click

Dim session As Object
Dim db As Object
Dim doc As Object

Set session = CreateObject("Notes.NotesSession")
Set db = session.D:\Project Tracker_120506\Analytical Request System
..db1.mdb
Set doc = db.CreateDocument
doc.Form = "Memo"
doc.Subject = "Here's the Project Information you Requested"
doc.Body = "Here it is"
Call doc.Send(False)
DoCmd.OpenForm "frmCMA PT", acNormal
DoCmd.Maximize
DoCmd.GoToRecord , , acNewRec

Exit_Add_Project_Click:
Exit Sub

Err_Add_Project_Click:
MsgBox Err.Description
Resume Exit_Add_Project_Click

End Sub
 
E

EAB1977

Try this:


Private Sub Add_Project_Click()
On Error GoTo Err_Add_Project_Click


Dim session As Object
Dim db As Object
Dim doc As Object
Dim rtitem As Object


Set session = CreateObject("Notes.NotesSession")
Set db = session.Current Database
Set doc = db.CreateDocument
doc.SendTo = 'Who is this being sent to? The email will fail unless
there is a person(s) to send to.
doc.Form = "Memo"
doc.Subject = "Here's the Project Information you Requested"
doc.Body = "Here it is"
Set rtitem = doc.CreateRichTextItem("Attachment")
Call rtitem.EMBEDOBJECT(1454, "", "D:\Project
Tracker_120506\Analytical Request System.db1.mdb"
Call rtitem.ADDNEWLINE(1, True)
Call doc.Send(False)
Set session = Nothing ' Unload the object
DoCmd.OpenForm "frmCMA PT", acNormal
DoCmd.Maximize
DoCmd.GoToRecord , , acNewRec

Exit_Add_Project_Click:
Exit Sub


Err_Add_Project_Click:
MsgBox Err.Description
Resume Exit_Add_Project_Click


End Sub
 
E

EAB1977

Opps. Forgot to mention.

The reason it failed was because you didn't set your Rich Text Item
(rtiItem) as a object.
 
L

Larry06Green

I currently have the email address information populated in a field on my add
project form. Can this information be referenced in the "Send To" line of the
code below? Also, is it possible to include a couple of field values in the
body of the email? Sorry to be sure a pain, but as you mentioned earlier,
using SendObject it just doesn't seem to work well with Lotus Notes.
 
L

Larry06Green

I currently have the email address information populated in a field on my add
project form. Can this information be referenced in the "Send To" line of the
code below? Also, is it possible to include a couple of field values in the
body of the email? Sorry to be such a pain, but as you mentioned earlier,
using SendObject just doesn't seem to work well with Lotus Notes.

Sub SendEmail()
Dim session As Object
Dim db As Object
Dim doc As Object
Dim rtitem As Object

Set session = CreateObject("Notes.NotesSession")
Set db = session.CurrentDatabase
Set doc = db.CreateDocument
doc.Form = "Memo"
doc.SendTo = ""
doc.Subject = "Here's the document you wanted"
doc.Body = "Here it is"
'If you need to send a attachment, uncomment and use
'Set rtitem = doc.CreateRichTextItem("Attachment")
'Call rtitem.EMBEDOBJECT(1454, "", "C:\Test.doc")
'Call rtitem.ADDNEWLINE(1, True)
Call doc.Send(False)
End Sub
 
E

EAB1977

I currently have the email address information populated in a field on my add
project form. Can this information be referenced in the "Send To" line of the
code below? Also, is it possible to include a couple of field values in the
body of the email? Sorry to be such a pain, but as you mentioned earlier,
using SendObject just doesn't seem to work well with Lotus Notes.


Yes, it can. I'm guessing your field has a name for the person to be
emailed. For example, if you have a text box named txtSendTo on a form
called frmEmail, you can do Me.txtSendTo.value, if the code is within
the form, or you can use Forms!frmEmail!txtSendTo if you have it in a
seperate module. So, it would look like this:

doc.SendTo = Me.txtSendTo.Value
or
doc.SendTo = Forms!frmEmail!txtSendTo

For your other question, it can be done too, like:

doc.Body = "This person, " & Forms!frmEmail!txtSendTo & ", is to be
emailed."

Just remember to use the quotes and the ampersand symbol to delegate
what is text and what is a value in a text box or dropdown box.
 

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