Object variable not set

Hi,

On click of the Save button,

I am getting the error “Object Variable not set”, before entering into the code.

Below is Save button code:

Sub Click(Source As Button)

Dim ws As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Dim doc As NotesDocument

Dim session As New NotesSession

Dim db As NotesDatabase

Dim viewUNID As NotesView

Dim docForDocLink As NotesDocument

Dim docOld As NotesDocument

Dim sUNIDForDocLink As String



Set uidoc = ws.CurrentDocument

If uidoc.EditMode <> False Then

	Call uidoc.Refresh

End If

Set doc = uidoc.Document

sUNIDForDocLink = doc.GetItemValue("UNIDForDocLink")(0)



Set db = session.CurrentDatabase

Set viewUNID = db.GetView("vUNID")

Call viewUNID.Refresh

Set docForDocLink = viewUNID.GetDocumentByKey(sUNIDForDocLink, True)



Set docOld = db.CreateDocument

Call docForDocLink.CopyAllItems(docOld, True)

Call docOld.Save(True, True)



Forall ITEM In docForDocLink.Items

	Call ITEM.Remove

End Forall

Call doc.CopyAllItems(docForDocLink, True)

Call docForDocLink.Save(True, True)



Call doc.ReplaceItemValue("SaveOptions", "0")

Call uidoc.Close	

End Sub

What may be the issue? kindly help on this.

Thanks in advance,

Kamal

Subject: Object variable not set

Start your debugger and then check where exactly the error is being thrown.

Always check whether an object is created or not using NOTHING statement like -

if not doc is nothing then

'do something

else

'object not created

end if

–Phani

Subject: Object variable not set

Hi

Try this

sUNIDForDocLink = doc.GetItemValue(“UNIDForDocLink”)(0)

=> sUNIDForDocLink = doc.GetItemValue(“UNIDForDocLink”)

if not docForDocLink is nothing then

Set docOld = db.CreateDocument

Call docForDocLink.CopyAllItems(docOld, True)

Call docOld.Save(True, True)

Forall ITEM In docForDocLink.Items

Call ITEM.Remove

End Forall

Call doc.CopyAllItems(docForDocLink, True)

Call docForDocLink.Save(True, True)

Call doc.ReplaceItemValue(“SaveOptions”, “0”)

Call uidoc.Close

end if

HTH

Subject: RE: Object variable not set

Thaks a lot Phani kiran & Yannick Michaudfor,

Thanks for you reply,

It is an Issue with the view which was not available.

Best Regards,

Kamal.