Puzzling SQL Execution Error

Here is the puzzling problem:

I trying to delete two records in SQL by Name. The count in the collection is 2. It will go through the first time, but when it gets to:

Set doc = ndc.GetNextDocument(doc)

It will then jump to the ErrorExe:.

Now here is the wierd part, It will remove the record from SQL.

Here is the Code:

Set ndc = db.UnprocessedDocuments

Set doc = ndc.getfirstdocument

Do While Not doc Is Nothing

  qrystr = {DELETE FROM dbo.Partners WHERE(Name = '} + doc.PartName(0) + {')}

  qry.SQL = qrystr

  result.execute

	

'Call doc.RemovePermanently(True)

Call ndc.DeleteDocument(doc)

	

Set doc = ndc.GetNextDocument(doc)

Loop

result.Close(DB_CLOSE)

con.Disconnect

ErrorExe:

Msgbox "Error during Execution"

Thanks for the help in advance.

Dave

Subject: Puzzling SQL Execution Error

You have deleted the doc, so there is no longer a pointer to the next document. You have a couple of options here. The easiest thing would be to wait until you finish processing the documents and then doing

Call ndc.Collection.RemoveAll( true )

Subject: RE: Puzzling SQL Execution Error

That worked. Thanks alot.

Dave

Subject: RE: Puzzling SQL Execution Error

Well, you need to get the next document before you delete the current document. You will need two NotesDocument variables.