"Object Variable not Set" error

I have this piece of code in the OnFocus event of a rich-text field, which adds a date/name “stamp” when the user accesses the field:

Dim ws As New NotesUIWorkspace

Dim uidoc As Notesuidocument

Dim session As New NotesSession

Dim db As NotesDatabase

Dim doc As NotesDocument

Dim rtnav As NotesRichTextNavigator

Dim rtpStyle As NotesrichTextParagraphStyle

Dim rtItem As Variant

Dim beginningText As Variant

Dim user As String

Dim intMonth As Integer

Dim currMonth As String

Dim currDay As Integer

Dim currYear As Integer

Set uidoc =ws.CurrentDocument

Set db = session.CurrentDatabase

Set rtItem = doc.GetFirstItem(“rtFull_Descript”)

Why do I get an “Object variable not set” error when it gets to “rtItem = doc.GetFirstItem(“rtFull_Descript”)”? rtFull_Descript is a rich-text field on the form.

By the way, IS “item” equivalent to “field”? Or do they mean different things, like “item” is a field’s value maybe?

Subject: RE: “Object Variable not Set” error

This error always refers to a variable that appears before the “.” – in this case, that would be “doc”. The variable “doc” was not set to an object value (in fact it wasn’t set at all).

Subject: RE: “Object Variable not Set” error

Dim ws As New NotesUIWorkspaceDim uidoc As Notesuidocument

Dim session As New NotesSession

Dim db As NotesDatabase

Dim doc As NotesDocument

Dim rtnav As NotesRichTextNavigator

Dim rtpStyle As NotesrichTextParagraphStyle

Dim rtItem As Variant

Dim beginningText As Variant

Set uidoc =ws.CurrentDocument

Set db = session.CurrentDatabase

→ Set doc = uidoc.Document

Set rtItem = doc.GetFirstItem(“rtFull_Descript”)

Set rtnav = rtItem.CreateNavigator

Thanks, Andre. I no longer get the same error for the “Set rtItem = doc.GetFirstItem…” line. However, while debugging the script, I noticed that that same line does not return anything. I checked the Items listed in “doc” and rtFull_Descript is not even listed there. In fact, not a one of all my rich-text fields is listed under ‘Items’. Therefore, I again get the same error for the next line “Set rtnav = rtItem.CreateNavigator”.

What am I doing wrong?

Subject: RE: “Object Variable not Set” error

Is the uidoc a new document? then you can’t access the items before the uidoc is saved.The fields can therefor only be accessed by the NotesUIDocument methods.

Subject: RE: “Object Variable not Set” error

That’s not exactly correct. Read the documentation for the NotesUIDocument.Refresh method to see how to load rich text fields into the NotesDocument.

Subject: RE: “Object Variable not Set” error

Yes, Andre. While browsing through rich-text field entries in this forum yesterday, I came across the NotesUIDocument.Refresh method. I tried it, and my code seems to be working fine now; just needs a little tweaking.Thank you, Andre and Urs, for your help.