Search DominoPower's 11,412 Lotus-related article archive 
Home
EasyPrint
News details Click here for the RSS feed's XML code. This is not a browser URL.
Articles-only Click here for the RSS feed's XML code. This is not a browser URL.
Twitter Feed Click here for the Twitter feed.
THIS WEEK'S POWERTIP
A Fix for folders and documents
By Mick Moignard

Oh, the perils of putting code in DominoPower articles! People might just try to run the stuff, and then find that it doesn't work.

No sooner had my piece on Folders and Lost Documents appeared on DominoPower (at http://www.DominoPower.com/issues/issue200310/00001122001.html), than I had an email from Peter Reilly who said:

I've pasted the [agent code] into an Agent. The agent is set to run on selected documents. From the All Documents View, I select 6 documents, and then run the agent from the Actions menu. I get the following error: "Document was deleted from this collection". Could you point me to what I might be doing wrong?

The short answer to Peter was nothing. The problem was in my code, not in what he'd done. I'd written it some years back to solve a particular problem, and must never have run into the error. So when I dragged the code out for the article, I just assumed it would work. Dumb, huh?

Here's the fragment of the code that illustrates the problem:

While Not(doc Is Nothing)
If doc.folderreferences(0) <> "" Then
Call doccoll.deletedocument(doc)
End If
Set doc = doccoll.GetNextDocument(doc)
Wend

The 'Document was deleted' message is issued when the GetNextDocument call is made. The GetNextDocument all gets the next document using the argument NotesDocument as a placeholder. So when the code removes a document from the collection, the GetNextDocument fails because the document passed in the argument isn't in the collection, so GetNextDocument has no idea where it is.

There are two solutions to this problem. Here's the first one -- and yes, I have tested this one!

01 Sub Initialize
02 Dim sess As New notessession
03 Dim db As notesdatabase
04 Set db = sess.currentdatabase
05 db.FolderReferencesEnabled = True
06 Dim doccoll As NotesDocumentCollection
07 Dim tempdoc As notesdocument
08 Set doccoll = db.AllDocuments
09
10 Set doc = doccoll.GetFirstDocument
11
12 While Not(doc Is Nothing)
13 If doc.folderreferences(0) <> "" Then 'doc is in at least one folder...
14 Set tempdoc = doc
15 Set doc = doccoll.GetNextDocument(doc)
16 Call doccoll.deletedocument(tempdoc) 'pull it from the collection
17 Else
18 Set doc = doccoll.GetNextDocument(doc)
19 End If
20 Wend
21 Call doccoll.PutAllInFolder("(Inbox)") 'all those that remain in the collection
22 End Sub

You can see that in Line 8 I have Dim'd another NotesDocument object. When I need to remove a document from the collection, I first make a copy of the reference to it to my spare NotesDocument -- that happens in line 14. Then in line 15 I can get the next document, because the current 'doc' is still in the folder. Line 16, I remove the saved document from the folder.


1  ·  2  ·  Next »
Other articles you might like
Home > Strategies > Email Management (60 articles)
   Using the Notes Client with Gmail
   Using the Notes client with Hotmail (or not)
   Is English-only a viable mail management strategy?
Home > Tips & Techniques (102 articles)
   More about Domino log files
   Why your log.nsf might not be purging properly
   A faster way to repair corrupted server files
Get Weekly Email Updates
Subscribe to our regular weekly email newsletter. It's packed with tips, reviews, deep analysis, and the latest news.
 
Recent DominoPower Articles
Application development, William Shatner, and the origin of the universe
The (near) future of Sametime, Quickr, Connections, and Symphony
Inside the IBM Innovations lab
Lotusphere 2010: Hot fixes and cool news for Notes, Domino, and LotusLive
Lotusphere 2010: mobility and collaboration
2010: A Lotusphere of change
Five trends for 2010
Latest Lotus Headlines
Flex: Using A SharedObject to Remember User Settings
Copy file instead of a link with Quickr connector in Notes
EclipseSource to Participate in Eclipse Foundation's Eclipse Training Series
CommonTime releases mDesign Studio
Quickr Domino 8.2 Fix Pack 10 is available
Sametime Business Cards: Where's that Picture Coming From?
How to let users define their own default font for Rich text fields
>> Read all the news
More from the ZATZ journals
Computing Unplugged: Make Mafia Wars an offer it can't refuse
David Gewirtz Online: CNN commentary and analysis
OutlookPower: Removing an Office installation that doesn't want to go away
-- Advertisement --

Find unused Lotus Notes groups and clean up your address book
Have you ever wanted to get rid of old Lotus Notes groups that were cluttering up your address book, but you weren't sure if they were used? Find Unused Groups can help.

Find Unused Groups will check your mail and ACL groups to help you determine if they are used, and who uses them.

Learn how to easily clean up your address book.

-- Advertisement --

Struggling with exporting Notes data to spreadsheets? No More!
Try IntelliPRINT, The world's leading Reporting, Dashboards, and Analysis solution for Notes & Domino

  • Don't spend unproductive time maintaining different versions of the same spreadsheet
  • Preserve data integrity and security in multi-user environments
  • Create reports in minutes INSIDE Notes
  • Get freedom from iterative report requests, deliver self-serve capabilities

Experience Reporting, Dashboards, and Analysis INSIDE Notes.

Try IntelliPRINT NOW!

ZATZ Home  ·  News  ·  Back Issues  ·  Credits/Trademarks ·  Link To Us
Copyright © 1998-2010, ZATZ Publishing. All rights reserved worldwide.
Editor's Login