Object Varible not set for a Rich Text field

I have a problem…I am trying to create a document where, right now will look to a specific document on another database and pull information and the attached file on that document into a new document on the current db. Here is the code:

Dim ses As New NotesSession

Dim profiledb As NotesDatabase

Dim profilelookupview As notesview

Dim profiledoc As notesdocument

Dim rtitem As NotesRichTextItem

Dim rtitem2 As NotesRichTextItem

Dim doc As NotesDocument

Dim newpcc As String

Set doc = source.Document

newpcc = “NGPHXLOC”

Set profiledb = ses.GetDatabase (“IPCRHUB001”, “Tools\Notes\regarc.NSF”)

Set profilelookupview = profiledb.GetView (“AllUserNames”)

Set profiledoc = profilelookupview.GetDocumentbyKey (newpcc, True)

Set rtitem = profiledoc.GetFirstItem( “Body” )

Set rtitem2 = doc.GetFirstItem(“IDFILe”)

'sets the document with the information from the document on the ReqXArchieve

doc.EmailName = newpcc

doc.EmailPassword = profiledoc.UserPassword(0)

Call rtitem2.AppendRTItem(rtitem) - this is where the error occurs

The text are populated with no issues, but when it comes to the attached file, I get Object Varible not set…What am I doing wrong here?

Thanks

Subject: Actually found a work a round for this

In my form I have a button which will send an email to whoever you specify. I moved the rtitem item to that function and it worked!

Subject: RE: Actually found a work a round for this

for future reference, see this for an explanation of the error and debugging techniques.

Debugging Domino Applications part 1 and part 2