Error Object Variable not set

Hi all,

i have a problem when i create a new doc. In a form, i have a action hotspot with this code.

If the user save the form before click into action hotspot, the code runs ok but if not, the error “Object variable not set” occurr in line:

Set rtf1 = currdoc.GetFirstItem(“DVPLoc”)

This is the code.

Sub Click(Source As Button)

Dim session As New NotesSession

Dim workspace As New NotesUIWorkspace

Dim uidoc As notesuidocument

Dim currdoc As notesdocument

Dim db As NotesDatabase

Dim collection As NotesDocumentCollection

Dim doc As NotesDocument

Dim rtf1 As notesrichtextitem	



Set db = session.CurrentDatabase

Set uidoc = workspace.CurrentDocument

Set currdoc = uidoc.Document

Set collection = workspace.PickListCollection(1, False, "Server", "Database.nsf", "View","DVP & R List", "Please select a DVP & R")

If collection.Count = 0 Then

	Messagebox "User canceled" ,, "No Documents selected to be linked." 

Else

	Set doc = collection.GetNthDocument(1)

	Set rtf1 = currdoc.GetFirstItem("DVPLoc")

	If rtf1.type = RICHTEXT Then

		If ( rtf1 Is Nothing ) Then

			Exit Sub

		Else 

			If doc.Codigo(0) <> "" Then

				Call rtf1.AppendText("DVP&R: ")

				Call rtf1.AppendDocLink(doc,"DVP&R")

			Else

				Call rtf1.AppendText("DVP&R: " & doc.FicoRef(0) &" is linked . Please click on the doclink to open the document")

				Call rtf1.AppendDocLink(doc,"DVP&R") 

			End If

		End If

	End If

End If

Call currdoc.save(True,False)

currdoc.saveoptions = "0"

Call uidoc.Refresh

Msgbox "DVP&R: " & doc.FicoRef(0) &" is linked ."&Chr$(10)&"The DVP&R link only appear after you save and close this document.",0,"DVP & R Link"

End Sub

Tanks

Subject: Error Object Variable not set

rich text fields do not appear on the back end document until it is saved for the first time so rtf1 will be nothing and when you test it on the next line it throws an error.

Try using uidoc.Refresh(True) before getting a handle on the rich text field

Subject: RE: Error Object Variable not set

Hi Matt

But if i use this instruction, i lost the information previous stored into uicod.

Subject: Error Object Variable not set

It is because the uidoc.document is NOTHING before the UIDoc is saved.

You can go one of two ways either:

put a Call uidoc.save() line in after you have verified that the collection is valid OR:

check to see if the currDoc is nothing before continuing. i.e.

if not currdoc is nothing then

'Continue with processing

else

Print “Could not get document handle. Please save before trying again.”

end if

Rob

Subject: RE: Error Object Variable not set

Thanks Rob

Its work fine.

Subject: RE: Error Object Variable not set

Although using uidoc.Save will stop you receiving an error message the logic behind Robs suggestion is not correct.

You can get a handle on the back end document using uidoc.Document for a new document and access all its fields using the notesdocument class apart from rich text fields which do not appear on the back end document until it is saved for the first time. uidoc.refresh(True) includes rich text fields from the front end on the back end document allowing you to access them.

There is the possibility that the user will use your action button to add the link and then decide that they don’t wish to save the document. If you have already saved it in your script then it will appear in the database.