SendNotesMail??

J

jo

Hi guys i was given this piece of code to help me send email from access via
lotus notes but everytime I try to change the headings to accomadate my
reports ect it gives me Compile Error Expected: Indentifier. Can you help?

This is the code:

Public Sub SendNotesMail(Subject As String, attachment As String, recipient
As String, bodytext As String, saveit As Boolean)

And this is what it rejects?

Public Sub SendNotesMail("Gauge Control", "Overdue.snp",
"(e-mail address removed)", "Gauges Overdue", False)
 
D

Douglas J. Steele

You don't change that particular line of code to accomodate your
requirements. You call the sub, passing it your values:

Call SendNotesMail("Gauge Control", "Overdue.snp",
"(e-mail address removed)", "Gauges Overdue", False)
 
J

jo

Hi Doug thanks for yr reply, confused? do I not change any thing then? how
does know what to look for? This the complete code which part do I need to
change?

Public Sub SendNotesMail(Subject As String, attachment As String, recipient
As String, bodytext As String, saveit As Boolean)
'Set up the objects required for Automation into lotus notes
Dim Maildb As Object 'The mail database
Dim UserName As String 'The current users notes name
Dim MailDbName As String 'THe current users notes mail database name
Dim MailDoc As Object 'The mail document itself
Dim AttachME As Object 'The attachment richtextfile object
Dim Session As Object 'The notes session
Dim EmbedObj As Object 'The embedded object (Attachment)
'Start a session to notes
Set Session = CreateObject("Notes.NotesSession")
'Get the sessions username and then calculate the mail file name
'You may or may not need this as for MailDBname with some systems you
'can pass an empty string
UserName = Session.UserName
MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) -
InStr(1, UserName, " "))) & ".nsf"
'Open the mail database in notes
Set Maildb = Session.GETDATABASE("", MailDbName)
If Maildb.IsOpen = True Then
'Already open for mail
Else
Maildb.OPENMAIL
End If
'Set up the new mail document
Set MailDoc = Maildb.CREATEDOCUMENT
MailDoc.Form = "Memo"
MailDoc.sendto = recipient
MailDoc.Subject = Subject
MailDoc.Body = bodytext
MailDoc.SAVEMESSAGEONSEND = saveit
'Set up the embedded object and attachment and attach it
If attachment <> "" Then
Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment")
Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", attachment,
"Attachment")
MailDoc.CREATERICHTEXTITEM ("Attachment")
End If
'Send the document
MailDoc.PostedDate = Now() 'Gets the mail to appear in the sent items
folder
MailDoc.SEND 0, recipient
'Clean Up
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj = Nothing
End Sub
 
D

Douglas J. Steele

You shouldn't have to make any changes.

Subs and functions both define arguments in their declaration line: the bit

Public Sub SendNotesMail(Subject As String, attachment As String, recipient
As String, bodytext As String, saveit As Boolean)

When you call the sub or function, you pass values for those arguments,
which are then referred to in the code. For instance, when you call the sub
using

Call SendNotesMail("Gauge Control", "Overdue.snp",
"(e-mail address removed)", "Gauges Overdue", False)

you've provided values for arguments Subject, attachment, recipient,
bodytext and saveit. In the sub, you can see code

MailDoc.sendto = recipient
MailDoc.Subject = Subject
MailDoc.Body = bodytext
MailDoc.SAVEMESSAGEONSEND = saveit

That's the equivalent to saying

MailDoc.sendto = "(e-mail address removed)"
MailDoc.Subject = "Gauge Control"
MailDoc.Body = "Gauges Overdue"
MailDoc.SAVEMESSAGEONSEND = False
 
J

jo

Hi Doug sorry to be pain! I have now change to part you have said and I am
not getting any errors but how do test this?

Changed too:

MailDoc.sendto = "(e-mail address removed)"
MailDoc.Subject = "Gauge Control"
MailDoc.Body = "Gauges Overdue"
MailDoc.SAVEMESSAGEONSEND = False

I also had this code to create a report then sendemail but SendObject does
send in Lotus that's why I needed my code changed. But I dont know where to
put or add theabove code new?

Function checker_Query_overdue()
On Error GoTo checker_Query_overdue_Err

If (DCount("*", "OnOpenOverdue") > 0) Then
DoCmd.SendObject acReport, "OnOpenOverdue", "SnapshotFormat(*.snp)",
"(e-mail address removed)", "", "", "Gauge Control", "Gauges Overdue",
False, ""
End If
If (DCount("*", "OnOpenOverdue") = 0) Then
Exit Function
End If
DoCmd.Close acReport, "OnOpenOverdue"
 
D

Douglas J. Steele

I'm sorry, you obviously misunderstood what I was trying to tell you.

As I prefaced my remarks, you shouldn't have to make any changes. What I was
trying to explain to you was how subs and functions work. They're written
generically, referring to named arguments, and then you pass values for
those arguments for them to use.

In other words, save the sub in a standard module (not a class module nor a
module related to a form or report). Do not change the code at all. Make
sure you do not name the module SendNotesMail (modules cannot have the same
names as subs or functions contained within them.)

You'll then use code to save your report as Overdue.snp, and then call the
sub, something like:

Function checker_Query_overdue()
On Error GoTo checker_Query_overdue_Err

DoCmd.OpenReport "OnOpenOverdue", acPreview
DoCmd.OutputTo _
acOutputReport, , acFormatSNP, _
Application.CurrentProject.Path & "\Overdue.snp", True
DoCmd.Close acReport, "OnOpenOverdue", acSaveNo

Call SendNotesMail("Gauge Control", Application.CurrentProject.Path &
"\Overdue.snp", "(e-mail address removed)", "Gauges Overdue", False)

(sorry, I never use snapshots, so I may have created the snapshot
incorrectly.)
 
J

jo

Ok Doug I really appreciate yr patients with me but I don know vba much at
all,
1. Do I create the Module under Objects in access? and call e.g Mail?
2. Do I need to alter my code that creates my report? e.g
Function checker_Query_overdue()
On Error GoTo checker_Query_overdue_Err"(e-mail address removed)", "", "", "Gauge Control", "Gauges Overdue",
False, ""
End If
If (DCount("*", "OnOpenOverdue") = 0) Then
Exit Function
End If
DoCmd.Close acReport, "OnOpenOverdue"
 
J

jo

Sorry about that I hit the wrong button!!
I am lost??
1.Do I use my code to create the report then add you code?
2.Is there any way you can put the code in order for me and tell where to
put it all.
3.How do I create a standard module do I just click on Module and not Class
Module?? Then add the code and save as any name except " SendNotesMail".
4. You say to Call something but how do I?, Call SendNotesMail("Gauge
Control", Application.CurrentProject.Path &
"\Overdue.snp", "(e-mail address removed)", "Gauges Overdue", False)

Thank you jo
 
D

Douglas J. Steele

Assuming that by your "code to create the report" you mean the snippet you
had that used SendObject

DoCmd.SendObject acReport, "OnOpenOverdue", "SnapshotFormat(*.snp)",
"(e-mail address removed)", "", "", "Gauge Control", "Gauges Overdue",
False, ""

you shouldn't require that. You showed

Function checker_Query_overdue()
On Error GoTo checker_Query_overdue_Err

If (DCount("*", "OnOpenOverdue") > 0) Then
DoCmd.SendObject acReport, "OnOpenOverdue", "SnapshotFormat(*.snp)",
"(e-mail address removed)", "", "", "Gauge Control", "Gauges Overdue",
False, ""
End If
If (DCount("*", "OnOpenOverdue") = 0) Then
Exit Function
End If
DoCmd.Close acReport, "OnOpenOverdue"

Instead, you want what I showed (although I left out a bit)

Function checker_Query_overdue()
On Error GoTo checker_Query_overdue_Err

If (DCount("*", "OnOpenOverdue") > 0) Then
DoCmd.OpenReport "OnOpenOverdue", acPreview
DoCmd.OutputTo _
acOutputReport, , acFormatSNP, _
Application.CurrentProject.Path & "\Overdue.snp", True
DoCmd.Close acReport, "OnOpenOverdue", acSaveNo

Call SendNotesMail("Gauge Control", _
Application.CurrentProject.Path & "\Overdue.snp", _
"(e-mail address removed)", "Gauges Overdue", False)
Else
Exit Function
End If


To create a standard module, you'd click on Module.

I've got the code to call the sub shown above.
 
J

jo

Hi Doug I have done the things you said to do, as for the call code I put
that into the module and I didn't give it a name as such its just Module1.
But it all stops once the report has been created and an error comes up
"Richtext Attachment already exits" and thats as far as it goes. Doesn't even
create the email at all?? Have I missed something out??
p.s thank you for all your help your a star!!
 
D

Douglas J. Steele

Sorry, but I'm not all that familiar with automating Lotus Notes (despite
the fact that we're currently using it at work...), and it would appear that
it's the code in SendNotesMail that's causing the problem.

Good luck!
 
J

jo

Ok Doug thanks for all your help with this and I do win with this I shall let
you know.
Thanks Jo
 
J

jo

Hi Doug it me again I found the problem with the code on the website and
needed to remove "MailDoc.CREATERICHTEXTITEM ("Attachment")" and that sovled
that problem!! And it emails correctly, But I would like to send to 3 people
plus a copy to myself but I do not know how to change the codes to
accommodate this would you able to help??
p.s the report page does not shutdown even though the code does say to close
report do I need to add that to SendNotesMail code??
Jo
 
J

jo

Hi Doug I did see that piece of code but to be honest I tried putting it to
my code but didn't work due to my lack of knowledge but I then came up with
putting the people into a group in lotus notes and called that group up and
it works!! But stil one problem left and that is the "Overdue.snp" report
does not close. I have tried adding
DoCmd.Close acReport, "Overdue.snp", acSaveNo
but no joy can you help me again plz jo
 
D

Douglas J. Steele

If you look back at what I said to do, I said you wanted to use

DoCmd.Close acReport, "OnOpenOverdue"

The fact that you've created a snapshot is irrelevant: it's the report
you're trying to close, not the snapshot.
 
J

jo

Hi Doug I have that already as you have said previously.. no joy though.. I
have even tried placing it in different place.. The actual Database closes
down as I wanted but the snap viewer is open still??
 
D

Douglas J. Steele

What opens the snapshot viewer? (to be honest, I've never created a
snapshot, preferring to use PDF files)

Recognize that the snapshot viewer isn't Access: it's a separate executable.
You should be able to use the code in
http://www.mvps.org/access/api/api0025.htm at "The Access Web" to shut it
down.
 
J

jo

Hi Doug just thought I would let you know and any body who may of been
folling this thread that I have solved the problem of closing the snapshot
viewer I had the code:
DoCmd.OutputTo _
acOutputReport, , acFormatSNP, _
Application.CurrentProject.Path & "\Overdue.snp", True

I have change to this:

DoCmd.OutputTo _
acOutputReport, , acFormatSNP, _
Application.CurrentProject.Path & "\Overdue.snp", False

Thanks for all your help
Jo
 

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