Problem with a loop

I need to get some properties from all Notes databases on a particular server. At the moment I have a loop that successfully runs through the first few hundred databases and then crashes with “Object variable not set”. I have debugged the code and the script is unable to set db. I cannot find any problems with the db that the database fails on.

Dim curdoc As NotesDocument

Dim db As NotesDatabase

Dim directory As NotesDbDirectory

Dim template As String

Dim collection As NotesDocumentCollection

Set curdb = s.CurrentDatabase

Set directory = New NotesDbDirectory("Notes01")



Set db= directory.GetFirstDatabase( DATABASE )





Do Until db Is Nothing

	Set db = directory.GetNextDatabase()

	Print db.FilePath



Loop

End Sub

Subject: Problem with a loop

Hi Alice,

You need to swap 2 lines of code- when the “Loop” hits the last database, you are still looking for one more, and it doesn’t exist.

Dim directory As NotesDbDirectory

Dim template As String

Dim collection As NotesDocumentCollection

Set curdb = s.CurrentDatabase

Set directory = New NotesDbDirectory(“Notes01”)

Set db= directory.GetFirstDatabase( DATABASE )

Do Until db Is Nothing

Print db.FilePath

Set db = directory.GetNextDatabase()

Loop

End Sub

Subject: RE: Problem with a loop

Yes

But, I do prefer the ‘while loops’, because my teachers told me it is better. lol

ian

Subject: RE: Problem with a loop

Does directory contain an object, or is it nothing ?

Subject: Problem with a loop

you wrote :

Do Until db Is Nothing

	Set db = directory.GetNextDatabase()

	Print db.FilePath

Loop

which is not particulary smart… :wink:

you should write :

Set db= directory.GetFirstDatabase( DATABASE )

while not db is nothing

print db.filePath

Set db = directory.GetNextDatabase()

wend

ian

Subject: RE: Problem with a loop

Thanks for your response.

I have tried using wend and moving the getnextdatabase line and the script still fails.

I have also tried this on other servers and get the same problem

Rgds

Subject: RE: Problem with a loop

What is your final source ?