Hi!
I’m confused. When I run my program, I get an “Object variable not set” error. This error doesn’t occur if I try to debug the code and press “enter into” on every step. If I press “enter into”, the program completes just fine (well, it isn’t ready, but without errors), but every other time it halts.
I know the line(s) where the problem is, but as far as I (newbie to ls) know there shouldn’t be any problems.
Problem occurs in for loop and it goes few times over before error.
Here’s my code so far:
Sub Querydocumentdelete(Source As Notesuidatabase, Continue As Variant)
Dim session As New NotesSession
Dim dc As NotesDocumentCollection
Dim doc As NotesDocument
Set dc = source.Documents
Set session = New NotesSession
Set doc = dc.GetFirstDocument()
Dim docCount As Integer
Dim userRole As Integer
Dim author As String
Dim user As String
Dim isAuthor As Boolean
docCount = dc.Count
user = session.UserName
userRole = session.CurrentDatabase.QueryAccess(user)
If docCount =< 0 Then
Messagebox ("Cannot delete! No documents selected")
Continue = False
Else
Dim i As Integer
i=1
For i=1 To docCount Step 1
'NEXT LINE IST WHERE THE ERROR IS “BORN”
Set doc = dc.GetNthDocument(i)
isAuthor = GetIsAuthor(doc, user)
If isAuthor = True Then
Call dc.DeleteDocument(doc)
Elseif userRole = 6 Then
Call dc.DeleteDocument(doc)
Else
Messagebox (“Only author or a database manager can delete this document”)
Continue = False
End If
Next
End If
End Sub
-And heres the function where the actual crash happens:
Function GetIsAuthor(curdoc As NotesDocument, user As String) As Boolean
Dim i As Integer
Dim length As Integer
i = 0
'AT NEXT LINE PROGRAM CRASHES
length = Ubound(curdoc.Authors)+1
On Error Resume Next
GetIsAuthor = False
While i< length
If user = curdoc.Authors(i)
Then
GetIsAuthor = True
Exit Function
End If
i = i+1
Wend
End Function
The problem is that for some reason “doc” is not set in the Querydocumentdelete. It sets few time fine, but then in 3rd of 4th loop it doesn’t.
Any ideas? I’m out of them.
Thanks!