This Script gets the outline folders and then searches for the folder “Fiscal Year 05’” however if that folder does not exist the while statement returns the error “Object variable not set” when it reaches the end of the folder list. The documentation states that when this happesn it should return null. but if I try to check for null using either “isnull(fiscnm) or fiscnum <> null” returns the same error. does anyone have a workaround?
Thanks in advance.
fiscnm = “Fiscal Year 05’”
Set outline = db.GetOutline(“Folders”)
Set entryA = outline.GetFirst()
While entryA.Label <> fiscnm Or entryA.Label <> Null
Set entryA=outline.GetNextSibling(entryA)
Wend
If Isnull(entryA.Label) Then
Messagebox "You Must Enter a Valid Year"
Goto gend
End If
Subject: Object Variable Not Set with outline.getnext
You are testing for Isnull outside of the loop, but the condition for the loop (the while) tries to check the value of an outline entry that isn’t there.
Subject: RE: Object Variable Not Set with outline.getnext
It is still giving the error. Here is the full script. Thanks
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim tmpfold As NotesView
Dim fldrnm As String
Dim fiscyr As String
Dim fiscnm As String
Dim outline As NotesOutline
Dim entryA As NotesOutlineEntry
Dim entryB As NotesOutlineEntry
Set db = session.CurrentDatabase
Picky:
fldrnm = Inputbox$("Name of new folder (MUST be in this Format: XX-XXX)","New Folder Number")
If fldrnm = "" Goto gend
chkfldr$ = Mid$(fldrnm,3,1)
If chkfldr$ <> "-" Then
Messagebox "Must be in this format XX-XXX"
Goto Picky
End If
chklen$ = Len(fldrnm)
If chklen$ <> 6 Then
Messagebox "Must be in this format2 XX-XXX"
Goto Picky
End If
fiscyr = Left$(Cstr(fldrnm), 2)
fiscnm = "Fiscal Year " + fiscyr + "'"
Set outline = db.GetOutline("Folders")
Set entryA = outline.GetFirst()
While entryA.Label <> fiscnm Or entryA.Label <> Null
Set entryA=outline.GetNextSibling(entryA)
If Isnull(entryA.Label) Then
Messagebox "You Must Enter a Valid Year"
Goto gend
End If
Wend
Set tmpfold = db.GetView("mail") 'get default folder template
tmpfold.CreateViewFromTemplate(Cstr(fldrnm)) 'create new folder based on template
Set entryB = outline.CreateEntry(Cstr(fldrnm),,,) 'create new outline entry
entryB.ImagesText = "spacer.gif" 'assign outline entry to have this image
Call entryB.SetNamedElement(db,Cstr(fldrnm), OUTLINE_CLASS_FOLDER) 'assign the folder to outline entry
Call outline.MoveEntry(entryB,entryA,True,True) 'move outline entry to a subentry
Call outline.Save
gend:
end sub
Subject: RE: Object Variable Not Set with outline.getnext
You can’t test ANY property of entryA if entryA is Nothing, and you are trying to test entryA.Label in your While statement. All you can test at that level is “is the entry Nothing”. So:
Set entryA = outline.GetFirst()
Do Until entryA is Nothing
.
.
.
Loop
Use If statements inside the loop to test for values.
Subject: RE: Object Variable Not Set with outline.getnext
Thanks Stan. It worked Great. I appreciate your help.
Here is the updated script:
Set outline = db.GetOutline("Folders") 'get outline
Set entryA = outline.GetFirst() 'get first outline entry
Do Until entryA Is Nothing 'loop thru entry untill the end
If entryA.Label = fiscnm Then 'if the label of the entry matches exit the loop
Exit Do
End If
Set entryA=outline.GetNextSibling(entryA) 'get the net sibling label
Loop 'end the loop
If entryA Is Nothing Then Goto thend 'if a match is never found exit the script