loItem = THISFORM.oMail.oInbox.Items[(CountUnreadItems+1)-X ] =loItem.move("CompletedMailBox")BTW, < pre > and < /pre > tags (w/o spaces) preserve code formatting and make it easier to read.
>* get Inbox name >thisform.oInbox=THIS.GetMailObject("MyInboxMailbox") > >procedure getmailobject >LPARAMETERS lcRequiredFolder > >* Create the necessary objects to get to the message >THIS.oApplication=CREATEOBJECT("Outlook.Application") >THIS.oNameSpace=THIS.oApplication.GetNameSpace("MAPI") >RETURN THIS.GetFolder(lcRequiredFolder) > >Procedure getfolder >Lparameters lcRequiredFolder > >Local lnFolderNumber, ; > lnLoop, ; > lcFolderName,; > lcFolderNameIn > >mexit=.F. > >lnFolderNumber=0 > >For ii=1 to this.oNameSpace.Folders.Count > >With THIS.oNameSpace.Folders[ii] > lcFolderName= .name > If LOWER(lcFolderName)=LOWER(lcRequiredFolder) > For lnLoop=1 TO .Folders.Count > lcFolderNameIn=.Folders[lnLoop].Name > If LOWER(lcFolderNameIn)= "inbox" > lnFolderNumber=lnLoop > mexit=.T. > Exit > Endif > Endfor > Endif LOWER(lcFolderName)=LOWER(lcRequiredFolder) > >Endwith >if mexit=.T. > exit >endif >Endfor > > If lnFolderNumber>0 > Return THIS.oNameSpace.Folders[ii].Folders[lnFolderNumber] > Else > Return NULL > Endif > >The above all works fine >* find "Completed" folder under this mailbox >If !isnull(THISFORM.oMail.oInbox) > For y=1 to THISFORM.oMail.oInbox.folders.count > If lower(THISFORM.oMail.oInbox.folders[y].name)="completed" > CompletedMailBox=THISFORM.oMail.oInbox.folders[y] > Exit > Endif > Endfor >* so far so good > >CountUnreadItems=THISFORM.oMail.oInbox.Items.Count && works >for x=1 to CountUnreadItems >* CRASHES HERE ON MOVE > THISFORM.oMail.oInbox.Items[(CountUnreadItems+1)-X ].move("CompletedMailBox") && move from oldest to newest in case new mail comes in >endfor>That's it!