Object variable not set error

I have an object variable not set error and can’t seem to locate the error in my code. can anyone else see my error? thanks

Sub Onchange(Source As Field)

Dim workspace As New NotesUIWorkspace

Dim ContextView As NotesView

Dim contextDoc As NotesDocument

Dim uidoc As NotesUIDocument

Dim session As New NotesSession

Dim context, contextStringDesc As String

Dim contextDesc As Variant

Dim db As NotesDatabase



Set uidoc = workspace.CurrentDocument

Set db = session.CurrentDatabase

Call uidoc.Refresh



'get the currently entered contextTag and display in form banner

context = uidoc.FieldGetText("m_dlgContextTag")

Call uidoc.FieldSetText("m_txtCompContext", context)



'select the decription for the currently entered context tag

Set contextView = db.GetView("m_viwContextTag")

Set contextDoc = contextView.GetDocumentByKey(context)

contextDesc = contextDoc.GetItemValue("ContextDescription")

contextStringDesc = contextDesc(0)



'set the current context description

Call uidoc.FieldSetText ("m_txtCompDesc", contextStringDesc)





'Refresh the document

Call uidoc.Refresh

End Sub

Subject: 2 things

  1. Set an ON ERROR errorhandler in your code, then you get the line via msgbox ERL$

  2. The contextView object is empty if the “m_viwContextTag” view can’t be found, but you don’t handle this. Instead, you go ahead and try to set the contextDoc, which will fail if the contextView object is NOTHING.

bad code:

Set contextView = db.GetView(“m_viwContextTag”)

Set contextDoc = contextView.GetDocumentByKey(context)

Thomas / IBM