Function requires a valid ADT argument

I’ve googled and searched the forums on this error message. This has nothing to do with a calendar entry and I have implemented the other suggestions. I am copying documents from a user’s archive to their mailfile on the server.

Here is a snippet of code where I am getting the error and some comments:

Set ArchiveDoc = folder.GetFirstDocument

While Not (ArchiveDoc Is Nothing)

Set MailDoc = ArchiveDoc.CopyToDatabase(dbMail)

'Copy each document to the same folder in the Mail database

Call MailDoc.PutInFolder(folder.Name, True)

’ Remove document from the collection of documents built from the Archive database AllDocs view

Set tempDocA = AllArchiveDocs.GetDocument(ArchiveDoc)

Set ArchiveDoc = folder.GetNextDocument(tempDocA)

’ Remove from collection

Call AllArchiveDocs.DeleteDocument(tempDocA)

I get the error just after the Set tempDocA line. This is not on every document. I have found it occurs on a document that is already in the target database (mailfile) in another folder.

I am wondering if it has something to do with the CopytoDatabase and then PutInFolder. Any ideas on how to get around this or anyone experienced this?

Subject: Function requires a valid ADT argument

This just occurred to me…the document had been removed from the collection (AllArchiveDocs) from the first time it was put in the folder…so technically ArchiveDoc is not in the collection AllArchiveDocs. And this is usually the cause of this error.

Now how do I get around this?