Delete from view - "Object variable not set" error

I did not have this before, but recently when I tried to delete documents from a view (select doc and press del button), there was this message saying “Object variable not set”.Strangely, I could still delete the document (a X is shown next to the doc and when F9 was pressed, the doc was subsequently deleted).

I would like to understand how to resolve the “Object variable not set” message.

I put debug on but there was no code execution…

I checked my ondelete event but it is not even called (until I press F9).

Please help!

JJ

Subject: Delete from view - “Object variable not set” error

For the database , check the database script , under event “Querydocumentdelete” .

(Goto Other → database resources → database script in domino designer)

“Getdocumentbykey” method must have been used there .

Cheers

Siddhartha

Subject: RE: Delete from view - “Object variable not set” error

This is my database Querydocumentdeleteis there a way to supress the error if there are no GetNthDocument(i)?

Sub Querydocumentdelete(Source As Notesuidatabase, Continue As Variant)

Dim deldoc As NotesDocument

Dim responsedocs As NotesDocumentCollection



Dim session2 As New NotesSession

Dim workspace1 As New NotesUIWorkspace

Dim uidoc2 As NotesUIDocument

Dim doc2 As NotesDocument

Dim itemdoc2 As NotesItem	

Dim i As Long

Dim varRoles As Variant	

Dim varIndex1 As Variant



varRoles=Evaluate("@UserRoles")

varIndex1=Arraygetindex(varRoles,"[Admin]")



Set uidoc2 = workspace1.CurrentDocument

Set doc2 = uidoc2.Document

Set itemdoc2 = doc2.getfirstitem("AssignmentChangeLog")



'Msgbox  Source.Documents.Count 	& " item(s) marked for deletion"



For i = 1 To source.Documents.Count

	Set	deldoc = source.Documents.GetNthDocument(i)

	itemdoc2.AppendToTextList( deldoc.Resource(0) & " (" & deldoc.hours(0) & "hrs) " & " has been released by: " & session2.CommonUserName )

	

	deldoc.AssignStatus = "Released"

	deldoc.Save True, True

	'deldoc.Responses.RemoveAll(True)

	

Next i



uidoc2.Refresh



' Only [Admin] can delete document

If Isnull(varIndex1) Then

	Continue = False

Else

	deldoc.Responses.RemoveAll(True)

	Continue = True

End If

End Sub

Subject: RE: Delete from view - “Object variable not set” error

Hi

I believe that the problem does not come from the getNthDocument,

but rather from workspace1.currentDocument

(when you are in a view, you have no current document.)

I think that you should search wich specific form action this code has been designed for.

And consider re-writing it, it is some bad programming sample :wink:

(i.e. you experience one side-effect, so …)

HTH

ian

ADDED: note that the code deletes the children docs too, it may have designed for it too…

Subject: RE: Delete from view - “Object variable not set” error

I basically have parent - child docs set up, so if parent is gone, the children will need to be deleted.

I also have an embedded view with strange business rules so I added a few code to work around that.

I was requested that when people press “del” key, the embedded doc should not be deleted, rather, a field should be updated (if del was pressed in the embedded view only). For any other view, del should delete the doc…

actually can you please give me a few pointers on how to write decent code? I basically picked up Notes scripts with no background/training (surfed the net and read help).

Subject: RE: Delete from view - “Object variable not set” error

Hi,Actually, I don’t think that deleting docs from an embedded view is a good idea

(not even sure that it is possible, I’m sick and at home, it may be the reason).

What kind of documents are you trying to delete, i.e. how are they related to the opened doc ?

Are they children, or restricted to a category, or… ?

ian