Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending a Lotus Note thru VBA (Access 2000) 1

Status
Not open for further replies.

batteam

Programmer
Sep 12, 2003
374
0
0
US
Does anyone have a way to enter text into the body part of the Note via text from VBA code in Access 2000?

I use the hyperlink property box to get Lotus Note to 'load' and have it fill in the Note's address and subject, but cannot find the way to enter my text into the Note's body.
It really is not even necessary to have the code send the Note automatically, only to have it fill in the 'body' part of the Note with my text.

Thanks. Any help here would be appreciated.
 
Code:
Dim rst As Recordset
    Dim notesdb As Object
    Dim notesdoc As Object
    Dim notesrtf As Object
    Dim notessession As Object
    Dim avarrecip() As Variant
    Dim avarattach(1) As Variant
    Dim i As Integer


 'make new mail message
        Set notessession = CreateObject("Notes.Notessession")
        Set notesdb = notessession.GetDatabase("", "")
        Call notesdb.OPENMAIL
        Set notesdoc = notesdb.CreateDocument
        Call notesdoc.ReplaceItemValue("Subject", "Put Subject Here")[COLOR=red]
        Set notesrtf = notesdoc.CreateRichTextItem("body")
        Call notesrtf.AppendText("Add Additional text here.")
        Call notesrtf.AddNewLine(2)
        [/color]
        Call notesrtf.EmbedObject(1454, "", avarattach(0), "Attachment")
        Call notesrtf.EmbedObject(1454, "", avarattach(1), "Attachment")
        
        'send message
        Call notesdoc.Send(False, avarrecip)
        Call LogEvent("Emails Sent to " & ListSelection & ".") 'log event
        Msgbox "Email sent.", vbOKOnly + vbInformation, "Email Sent"
        Set notessession = Nothing

From the thread I referenced in the other post, the RED is where the BODY of the email is created.

Leslie
 
lespaul: you must monitor all the forums. Thanks for responding but I'll have to admit your code, once I started looking at it, is a little intimidating. Is it possible for you add some comments in it to explain what it most of it means? For example, are there other functions that go along with this? And, when you call notesrtf, are you only adding one line of text? and, what exactly does Call Notesdb.OPENMAIL do? or 'Call notesdoc.Send(False, avarrecip)'
It all seems to simple - like there's something missing.
I'm familiar with the SendObject in Access but I don't recognize much of this code.

We're using Lotus Notes ver. 5.010. Thanks again if you can help more.
 
OK,

No I don't monitor ALL the forums, but Access and Notes are two that I do (plus Delphi!).

First off, do you have access to the Notes Designer program? That's where you will get information about all the Notes commands. I'm using Notes 6.0 and things have changed a little, there are actually VB examples, so some of what I may tell you might be incorrect for your version.

Secondly, the OPENMAIL command opens the current users mailbox.

this command creates a rich text area for the body of the email:
Code:
Set notesrtf = notesdoc.CreateRichTextItem("body")


this command adds the 'Add Additional text here' to the body of the email:
Code:
Call notesrtf.AppendText("Add Additional text here.")

this command appends one or more new lines (carriage returns) to the end of a rich text item
Code:
Call notesrtf.AddNewLine(2)

here's the help on the AddNewLine
Call notesRichTextItem.AddNewLine( n% [, forceParagraph ] )
Parameters
n%
Note In COM this parameter is optional and defaults to 1.
Integer. The number of new lines to append.
forceParagraph
Boolean. Optional. If True, forces the new line to be a paragraph separator. If False, the new line is added, but does not force a new paragragh. True by default.

Here's is a little bit easier code for creating a simple email, but this example is in Lotus Script and would have to be modified a bit to work in VB: (I actually get information from another document in Notes so this will look wierd!)

Code:
Dim workspace As New NotesUIWorkspace
Dim session As New NotesSession
Dim db As NotesDatabase
Dim newdb As NotesDatabase
Dim doc As NotesDocument
Dim maildoc As NotesDocument
Dim mailrtitem As NotesRichTextItem
Dim language As String, docket As String, fname As String, lname As String, interveiwer As String, notify As String
Dim Comments As String
Dim intdate As Variant

'set current session to current document so information can be transferred to mail document
	
Set db = session.CurrentDatabase
Set servername = New NotesName(db.Server)

'set information for mail

domainmailfile = "mail.box"
Set newdb = session.GetDatabase(servername.Abbreviated, domainmailfile)

'create new maildocument

Set maildoc = New NotesDocument(newdb)

'check my data to see if I need to send the email or not

Set doc = source.Document
If (source.FieldGetText("InterviewLanguage") = "Other" And source.FieldGetText("OtherLanguage") <> "") Then

  'create list of people to send to (this way will only work if they are in YOUR mail directory, you would need to spell out the email address if not in your directory)

  Dim recipients( 1 To 2 ) As String
  recipients( 1 ) = "John Doe"
  recipients( 2 ) = "Jane Smith"

'only send if a new document, if someone has edited an existing document I don't want to send the notification		
  If source.document.IsNewNote Then
    'get all the information for the body of the email

    language = source.FieldGetText("OtherLanguage")
    docket = source.FieldGetText("DocketNo")
    fname = source.FieldGetText("FirstName")
    lname = source.FieldGetText("LastName")
    intdate = source.FieldGetText("InterviewDate")
    interviewer = source.FieldGetText("Interviewer")

    'assign the new document to an email form
		
    maildoc.Form = "Memo"

    'add subject line to email

    maildoc.Subject = "Translator Needed"

    'add body of email with information from above
	
    maildoc.Body = "Case Number: " + docket + ".      " +  fname + " " + lname  + " , interviewed on " + intdate + " by " + interviewer + ", requires a " + language + " translator.  Thank you."

    'send the email False indicates I don't want to attach the document and recipients is who is getting the email			
    Call maildoc.Send( False, recipients )
  Else
    Exit Sub
  End If
End If

so here are two different ways of creating the body of the email. The first one I gave you is already in VB, the second one is Lotus Script and will have to be modified to work in VB.

If you don't have access to Domino Designer I would ask for it to be installed. It will be easier for you (if you can decipher Notes help logic!!) on some basic functions.

HTH

and if you need anything else, feel free to post back, I'll be lurking around some forum!

Les
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top