First of all, apologies for the cryptic title! I couldn't really think of a way to put it concisely!
So, I have an Access ADP project (which many of you will feel you know intimately now!!) and one of its functions is to scan an email inbox looking for email from certain recipients, it then calls a stored procedure that inserts the data it finds into the SQL 2000 database.
This procedure works very well but I have the option on the form that calls the routine to delete the email when it has been imported into the database. When this is checked the routine only scans 50% of the emails (see the code snippet to see the line that does this) so I can kind of see what it is doing (when it looks for "next itm" the last one has been deleted so it gets confused I guess) but haven't a clue how to resolve it.
The function that does it is very long but the relevant bits (I guess) are: (I have omitted declarations etc)
Has anyone else come across a similar problem or any suggestions as to the solution?
Set appOutlook = GetObject(, "Outlook.Application")
Set nms = appOutlook.GetNamespace("MAPI")
If SelectFolder = True Then
Set fld = nms.PickFolder
lngItemCount = fld.Items.Count
For Each itm In fld.Items
If itm.Class = 43 Then '43 is the constant olMail
Set Safeitm = CreateObject("Redemption.SafeMailItem")
Safeitm.Item = itm
For Each att In Safeitm.Attachments
Set stm = New ADODB.Stream
.Type = adTypeBinary
'THE BIT THAT OPENS THE WORD ATTACHMENT, EXTRACTS THE DATA AND CALLS THE STORED PROCEDURE
If Me.chkDeleteEmail True Then Safeitm.Delete
Set Safeitm = Nothing