Lotus Notes: Getting "Object Variable Not Set" in the multiple doclink code below

2.3k Views Asked by At

The snippet of code below is that, the mail is first prepared, then a doclink is added for every document, and in the end the mail is being sent.

I am getting object variable not set at doc.SentTo = addresses.abbreviated

Dim s As NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim rtitem As NotesRichTextItem
Dim i As Integer
Dim view As NotesView

Set s = New NotesSession
Set db = s.CurrentDatabase
Set view = db.GetView("View")
Set doc = New NotesDocument(db)
Dim addresses As NotesName
i=0
'- prepare mail
doc.SendTo = addresses.abbreviated
doc.Form = "Memo"
Set rtitem = New NotesRichTextItem(doc, "Body")
Call rtitem.AppendText("Balance")

Set doc = view.GetFirstDocument
While Not(doc Is Nothing)
    Set addresses = New NotesName(doc.Manager(0)) 
    If addresses.abbreviated = "" Then
    i = i + 1
Else 
    '- Append descriptive text, link and new line
    Call rtitem.appendtext(doc.Subject(0) & "  " )
    Call rtitem.appenddoclink(doc, "Link")
    Call rtitem.addnewline(1)
    i = i + 1
End If
Set doc = view.GetNextDocument(doc)
Wend
'- send mail
Call doc.Send (True)

Help will be greatly appreciated.

1

There are 1 best solutions below

0
On

I see two problems here. One is that addresses hasn't been set to an object yet. The other is that you've used the doc variable for the email you want to send and for iterating through a set of documents.

Change these lines:

Set doc = New NotesDocument(db)
Dim addresses As NotesName

To this, or something similar:

Set mailDoc = New NotesDocument(db)
Dim addresses As New NotesName("email recipient user name")

mailDoc.SendTo = addresses.abbreviated
mailDoc.Form = "Memo"
Set rtitem = New NotesRichTextItem(mailDoc, "Body")

Also change the doc variable at the bottom to mailDoc :)