Copying rich text item

We already have some code which allows a user to select multiple questions, and then hit a button which allows them to enter a standard response and answers all those questions with the same text. At the moment, just copies plain text as the answer, but I want to copy rich text and keep all the formatting.

Basically when a user hits the ‘Bulk Answer’ button, it presents them with a form which allows them to enter the standard response. I’m playing around with this form firstly to see if I can copy rich text, and this is where I’m having the problem. In the code I’ve been testing with, I want it to copy the rich text item (in ‘standard response’ field), and create a new document and paste the rich text from standard response in. When I do this, it comes up with an Object Variable not set error. I’ve looked through help and it seems like I’m doing it right, but obviously not! Thanks in advance, code is shown below:

Sub Queryclose(Source As Notesuidocument, Continue As Variant)

Dim Workspace As New NotesUiWorkspace

Dim UiDoc As NotesUIDocument

Dim Session As New NotesSession

Dim SelectedQuestions As NotesItem

Dim rtitem As String

Dim rtitem2 As String



     '// If the user presses cancel then dont do anything

If Source.Document.CreateDocuments(0) = "No" Then

	Exit Sub

End If



 '// Begin Creating the Advice for each selected Document

Set SelectedQuestions = Source.Document.GetFirstItem("SelectedQuestions")

Dim DocA As NotesDocument

Set DocA = Source.Document



 '// Create the Advice Documents

If (Source.Document.DocumentType(0) = "Advice") Then

	Call CreateBulkAdviceForMany(SelectedQuestions)          

Else

  '    '// Create the Answer Documents

	

			'JUST TESTING

	Dim database As NotesDatabase

	Set Database = Session.CurrentDatabase

	Dim logdoc As NotesDocument

	Dim Testing As NotesRichTextItem

	Dim dummyitem As NotesRichTextItem

	Set logdoc = Database.CreateDocument

	

	logdoc.form = "EventLog2"

	

	

	Set dummyitem = Source.Document.GetFirstItem("StandardResponse")

	Set Testing = logdoc.GetFirstItem("LogAction")

	

	Call dummyitem.AppendRTItem(Testing)

	Call logdoc.Save( True, True )	

	'JUST TESTING

End If

Exit Sub

End Sub

Subject: Copying rich text item

Can you please tell which line in the code is producing the error message? Normally you get the “Object variable not set” message if one of the variables you are using is not initialized and you try to access properties or methods of that object.

Aniz

Subject: RE: Copying rich text item

Hi Aniz,

the code is falling down on the following line:

Call testing.AppendRTItem(dummyitem)

I also noticed in the debugger, under the Variables tab, both dummyitem and Testing don’t seem to have anything assigned against them. Not sure why, but could this be causing the problem?

Subject: RE: Copying rich text item

Just one more point,

Dim Testing As NotesRichTextItem

Dim dummyitem As NotesRichTextItem

I think you may need to declare them as variants. Since you have declared them a NotesRichTextItem, it may not be possible to initialize using GetFirstItem method.

Subject: RE: Copying rich text item

HI Aniz,

I added the following code which checks for the ‘Standard Response’ item:

	If Source.Document.HasItem("Standard Response") Then

		Messagebox "Has Standard REsponse"

	Else

		Messagebox "Doesn't have standard response"

	End If

It comes up with the message box that it DOESN’T have a standard response. There is definitely a rich text field on the document called “StandardResponse”. Any ideas why this might be happening?

Subject: RE: Copying rich text item

Jason, Yes, that could be the problem for sure. I would suggest that you look at these two lines.

Set dummyitem = Source.Document.GetFirstItem(“StandardResponse”)

Set Testing = logdoc.GetFirstItem(“LogAction”)

The Source.Document may not be having an item called StandardResponse and the logdoc may not be having an item called LogAction. Before you use GetFirstItem, it would be a good idea to check if the item exists in the document. That is by using HasItem method.

HTH

Aniz