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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

COMPOSEDOCUMENT - Lotus Notes Progamming

Status
Not open for further replies.

JonEvans

Technical User
Aug 16, 2001
3
GB
Help!!!

I`ve written a program in VB to connect to my Domino server and compose a new Lotus Notes Memo. I think the code is right as the memo is created however the document object does not seem to return a value and i get a "-2147417851 Automation error, The server threw an exception." error.

I need to return the document id as i want to add an attachment to it later...

here is the code
------------------------------------------------------------

Option Explicit
Public Sub connecttolotus(ServerName As String)

On Error GoTo Error_Trap

Dim ws As Object
Dim uidoc As Object
Dim AttachME As Object
Dim EmbedObj As Object
Dim NewMdName As String
Dim NotesSession As Object
Dim NotesUsername As String
Dim Attachment As String
Dim MailDbName As String
Dim MailCounter As Integer

Set NotesSession = CreateObject("Notes.NotesSession")
NotesUsername = NotesSession.USERNAME

Attachment = "c:\as400.log" ' add an attachment filename
NewMdName = "" ' initialise the username file

'Get the engineer username and then calculate the mail file name
MailDbName = Mid$(NotesUsername, 4, 1) & Right$(NotesUsername, (Len(NotesUsername) - InStr(1, NotesUsername, " ")))
For MailCounter = 1 To Len(MailDbName)
If Mid(MailDbName, MailCounter, 1) <> &quot;/&quot; Then
NewMdName = NewMdName & Mid(MailDbName, MailCounter, 1)
Else
Exit For
End If
Next MailCounter
MailDbName = &quot;mail\&quot; & NewMdName & &quot;.nsf&quot;
' Connect to Lotus Notes and Compose Document
Set ws = CreateObject(&quot;Notes.NotesUIWorkspace&quot;)
Set uidoc = CreateObject(ws.COMPOSEDOCUMENT(ServerName, MailDbName, &quot;Memo&quot;, 10, 10))

'Add the attachment
Set AttachME = uidoc.CREATERICHTEXTITEM(&quot;Attachment&quot;)
Set EmbedObj = AttachME.EMBEDOBJECT(1454, &quot;&quot;, Attachment, &quot;Attachment&quot;)
uidoc.CREATERICHTEXTITEM (&quot;Attachment&quot;)

'Refresh the Window
uidoc.RELOAD
End
Exit Sub


Error_Trap:
'Trap any Errors
MsgBox (&quot;Error : &quot; & Err.Number & &quot; &quot; & Err.Description)
Resume Next
End Sub
 
Jon,

I am not sure how helpful it is, but here is some code I have used to send Notes mail:
------------------------
Option Explicit

Private Const msDATABASE As String = &quot;TestApp.nsf&quot;

Private mobjSession As Object
Private mobjDb As Object

Private Sub Class_Initialize()
' Connect to Notes
1 Set mobjSession = CreateObject(&quot;Notes.Notessession&quot;)
End Sub

Public Sub Connect()
' Connect to Notes Database used for sending mail
On Error GoTo Error_Routine

1 Set mobjDb = mobjSession.GETDATABASE(&quot;&quot;, msDATABASE)
2 If Not mobjDb.ISOPEN Then
3 Call mobjDb.Create(&quot;&quot;, msDATABASE, True)
4 End If

Exit_Routine:
Exit Sub
Error_Routine:
Err.Raise Err.Number, &quot;clsMail.Connect(&quot; & Erl & &quot;):&quot; & Err.Source, Err.Description
End Sub

Public Sub Send(ByVal psText As String, ByVal psRecipient As String)
' Send mail
On Error GoTo Error_Routine

1 Dim objDoc As Object

2 Set objDoc = mobjDb.CREATEDOCUMENT()
3 objDoc.Form = &quot;Memo&quot;
4 objDoc.Subject = &quot;Mail from test application&quot;
5 objDoc.Body = psText
6 Call objDoc.Send(False, psRecipient)

Exit_Routine:
Exit Sub
Error_Routine:
Err.Raise Err.Number, &quot;clsMail.Send(&quot; & Erl & &quot;):&quot; & Err.Source, Err.Description
End Sub
--------------------
Glyn.
 
Cheers GlynA, I`ve seen this code before..My problem is that I don`t actually want to send the Notes mail, simply show the Note UI to allow the Users to add more recipients etc...doesn`t the code you gave me actually send the message all from the VB application?

Thanks again
 
Jon,

Yes, you are right, my code sends the mail from the VB application. The VB application contains some more routines to allow the user to select a recipient from Notes address books. I am afraid I have never tried displaying the Notes UI to do that.

Sorry to be no more help.

Glyn.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top