Click to See Complete Forum and Search --> : Bringing up Notes database from vb


gaudetl
April 10th, 2001, 07:25 AM
Hi
I need to send a attachment through lotus notes. I have found code that will do this, however what I need to be able to do is bring up the attachment in notes but have the user decide to send it or not. The following code adds the attachment and sends it off to a specified recipient. I want to modify the code so the attachment is put in the mail object but then the mail object opens up to let the user decide to whom he wants to send it to. Here is the procedure. I have been working on this for 2 days now with no luck. Any help is appreciated.

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

neal wilkinson
July 26th, 2001, 03:17 AM
You have basically got it, but you need to bring the maildoc into the workspace of the Notes environments and place it into edit mode to allow the user to select the recipients. Also, the maildoc.send will automatically route the document to the recipients in the background. I'm not sure of the vb code, but in notes it would looks something like:

dim db as notesdatabase
dim s as new notessession
dim ws as new notesuiworkspace ' ui interface
dim doc as new notesdocumen(db) ' backend doc
dim uidoc as notesuidocument ' frontend doc

set db = <your code>
set doc = db.composedocument()
doc.form = "memo"
doc.Subject = subject
doc.body = <your code for attachment>
set uidoc = doc.document
uidoc.editmode = true

This will compose the mail in the background, then bring the document into the foreground for the user to use the normal notes method to select the recipients, then send as normal

Hope this helps