I have an agent I want to act on every doc in view and send email. However, it is only sending email for first document. Can anyone help me to modify code so it will act on all docs and send email for all docs in view. The code is below…thanks in advance
Sub Initialize
Dim v As notesview
Dim dc As notesdocumentcollection
Dim emaildoc As notesdocument
Dim doc As notesdocument
Dim db As notesdatabase
Dim session As New notessession
Dim ws As New notesuiworkspace
Dim key As String
Set db = session.currentdatabase
Set v = db.getview("intro")
Set emaildoc = session.documentcontext
If emaildoc Is Nothing Then
Msgbox " Please single click on an email address to generate emails"
Exit Sub
End If
key = emaildoc.emailadd(0)
Set dc = v.GetAllDocumentsByKey(key)
'Set doc = dc.getfirstdocument()
Set doc = v.getfirstdocument
'Set emaildoc = db.CreateDocument
emaildoc.form = "memo"
Set emaildoc = db.CreateDocument
emaildoc.subject = "Graduate Survey for 2009/10 academic year"
emaildoc.saveoptions = "0"
emaildoc.copyto="Johnnie.Williams"
emaildoc.replyto=doc.Chair(0)
emaildoc.principal=doc.Chair(0)
emaildoc.url=doc.theurl(0)
While Not(doc Is Nothing)
emaildoc.sendto = doc.EmailAdd
Set rtitem = New NotesRichTextItem(emaildoc, "body" )
Call rtitem.AddNewline(2)
Call rtitem.AppendText("Congratulations on your decision to attend Spelman College! We would like to encourage you to participate in a brief survey for more details please click the link below: ")
Call rtitem.AppendText(doc.theurl(0))
If Not(doc Is Nothing) Then
emaildoc.Chairperson = doc.Chair
emaildoc.Department = doc.dept
End If
Call rtitem.AddNewline(2)
Call rtitem.AppendText("Sincerely")
Call rtitem.AddNewline(2)
Call rtitem.AppendText(doc.Chair(0))
Call rtitem.AddNewline(1)
Call rtitem.AppendText(doc.dept(0))
Call rtitem.AddNewline(1)
Call emaildoc.send(False)
Set doc = v.getnextdocument(doc)
Wend
End Sub