Search DominoPower's 11,323 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
Lotusphere 2010: mobility and collaboration
2010: A Lotusphere of change
Five trends for 2010
DominoPower TV Episode 1: Inside a strategy session with Teamstudio
More about Domino log files
Say goodbye to the Uh-Ohs. Long live the Tens.
Why your log.nsf might not be purging properly
Latest Lotus Headlines
Recommended Maintenance - Lotus Notes Traveler
Here are the slides and other materials from our Lotusphere session
Microsoft OCS awareness in Lotus Connections and Websphere Portal?
SnTT: XPages Blank Calendar Control (Part 2), adding data
Have your Lotus Notes calendar display multiple time zones
Sample Database for Microsoft Office and Lotus Symphony Integration
Symphony 3.0 beta signals another attack on Office
>> Read all the news
More from the ZATZ journals
Computing Unplugged: The iPad: Apple's latest heartbreaker
David Gewirtz Online: CNN commentary and analysis
OutlookPower: Running auto-respond rules when Outlook is closed
-- Advertisement --

Sophisticated Meets Simple For Document Management
Share. Control. Manage.
Documents, emails, and content in the context of how work is done. Native to Lotus Domino. The User Experience unseen for Lotus Domino. Do more with less. Really.

See the possibilities Docova unleashes for Lotus Domino.
-- Advertisement --

Integrate your Notes Applications with Microsoft Office and Symphony
Integra for Notes Integrates Microsoft Office and/or IBM Lotus Symphony
Requires NO change to the design of the appliation or Installations of DLL's and EXE's
  • Integra is a ready to use solution, enhance static reports with Excel data analysis, pivot tables, macros
  • User friendly aproach, using a point and click access to features
  • Reports from any Lotus Notes databases
  • Runs reports through a Notes client, web browser and scheduled basis
  • Allows use of LotusScript for advanced data manipulation
  • Enables self service reporting capabilities to end-users


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