I have the following code which works in the agent for the rich text field but does not work when i implement the same code on the button of the form. Can anybody help me to modify the code so that it works on a button on the form.
On Error Goto errhandler
Dim ws As New NotesUIWorkspace
Dim db As NotesDatabase
Dim uid As NotesUIDocument
Dim doc As NotesDocument
Dim MailDoc As NotesDocument
Set db = ws.CurrentDatabase.Database
Set uid = ws.CurrentDocument
Set doc = uid.Document
Call uid.Refresh
Set MailDoc = db.CreateDocument
MailDoc.Form = "Memo"
Dim recipients() As String
Dim cnt As Integer
cnt = 1
'Code modified by Sameer Damania on 7th May 2009
If Trim(doc.MType(0))="Ma" Then
Forall x In doc.SupportSite
Redim Preserve recipients(cnt) As String
recipients(cnt) = x
cnt = cnt + 1
End Forall
Else
Forall y In doc.SiteSupport
Redim Preserve recipients(cnt) As String
recipients(cnt) = y
cnt = cnt + 1
End Forall
End If
'End of Code modified by Sameer Damania
Dim Item As NotesItem
Set Item = doc.GetFirstItem("Comments")
MailDoc.Subject = Item.Text + " - " + doc.RequestType(0) + " - " + doc.FirstName(0) + " " + doc.LastName(0) + " - <ID Completed>"
Dim MailBody As NotesRichTextItem
Set MailBody = New NotesRichTextItem(MailDoc, "Body")
Call MailBody.AppendText("Hi,")
Call MailBody.AddNewLine(2)
Dim IDFile As NotesRichTextItem
Set IDFile = doc.GetFirstItem("IDFile")----> gives me an error on this line that is object variable not set.
Call MailBody.AppendText("New notes ID file for --> " + doc.FirstName(0) + " " + doc.LastName(0) + " --> ")
Dim object As NotesEmbeddedObject
Dim folderName As String
Forall o In IDFile.EmbeddedObjects
folderName = "c:\NotesIDFiles"
If Not (isFolder(folderName)) Then
Mkdir(folderName)
End If
Call o.ExtractFile( folderName + "\" + o.Source )
Call MailBody.EmbedObject(o.Type,"",folderName + "\" + o.Source)
Kill(foldername + "\" + o.Source)
End Forall
Rmdir(folderName)
Call MailBody.AddNewLine(2)
Call MailBody.AppendText( "Requested By --> " + doc.RequestedBy(0))
Call MailBody.AddNewLine(2)
Call MailBody.AppendText( "Thanks & Regards," )
Call MailBody.AddNewLine(1)
strconst = {@Name([CN];@UserName)}
eval = Evaluate(strconst)
Call MailBody.AppendText(eval(0))
Call MailBody.AddNewline(1)
Call MailBody.AppendText("GSA_GlobalSecurityAdmins.")
Call MailDoc.ReplaceItemValue("Principal","GSAGlobalSecurityAdmins") ' Added by Sameer Damania to incorporate the sending of id file and password from your own login
MailDoc.BlindCopyTo = "GlobalSecurity_Admins@colpal.com"
If Trim(doc.SupportSite(0)) = "Asia Pacific Helpdesk/AULSY/AP/COLPAL" Or Trim(doc.SupportSite(0))="Malaysia Helpdesk/MALKL/AP/COLPAL" Or Trim(doc.SiteSupport(0)) = "Asia Pacific Helpdesk/AULSY/AP/COLPAL" Or Trim(doc.SiteSupport(0)) = "Malaysia Helpdesk/MALKL/AP/COLPAL"Then
MailDoc.EncryptOnSend = False
Else
MailDoc.EncryptOnSend = True
End If
Call uid.Save
Call MailDoc.Send(False,recipients)
Set MailDoc = db.CreateDocument
MailDoc.Form = "Memo"
MailDoc.Subject = Item.Text + " - " + doc.RequestType(0) + " - " + doc.FirstName(0) + " " + doc.LastName(0) + " - <Password Completed>"
Set MailBody = New NotesRichTextItem(MailDoc, "Body")
Call MailBody.AppendText("Hi,")
Call MailBody.AddNewLine(2)
Call MailBody.AppendText("The password for the user --> " + doc.FirstName(0) + " " + doc.LastName(0) + " --> " + doc.IDPassword(0))
Call MailBody.AddNewLine(2)
Call MailBody.AppendText( "Requested By --> " + doc.RequestedBy(0))
Call MailBody.AddNewLine(2)
Call MailBody.AppendText( "Thanks & Regards," )
Call MailBody.AddNewLine(1)
strconst = {@Name([CN];@UserName)}
eval = Evaluate(strconst)
Call MailBody.AppendText(eval(0))
Call MailBody.AddNewline(1)
Call MailBody.AppendText("GSA_GlobalSecurityAdmins.")
Call MailDoc.ReplaceItemValue("Principal","GSAGlobalSecurityAdmins") ' Added by Sameer Damania to incorporate the sending of id file and password from your own login
MailDoc.BlindCopyTo = "GlobalSecurity_Admins@colpal.com"
If Trim(doc.SupportSite(0)) = "Asia Pacific Helpdesk/AULSY/AP/COLPAL" Or Trim(doc.SupportSite(0))="Malaysia Helpdesk/MALKL/AP/COLPAL" Or Trim(doc.SiteSupport(0)) = "Asia Pacific Helpdesk/AULSY/AP/COLPAL" Or Trim(doc.SiteSupport(0)) = "Malaysia Helpdesk/MALKL/AP/COLPAL"Then
MailDoc.EncryptOnSend = False
Else
MailDoc.EncryptOnSend = True
End If
Call MailDoc.Send(False, recipients)
Msgbox "Mail Sent"
Exit Sub
errhandler:
Msgbox "Error " + Error + " : Error line " + Cstr(Erl)
Exit Sub
End Sub