View Single Post
  #10  
Old July 22nd 09, 04:41 PM posted to microsoft.public.outlook.program_vba
Michael Bauer [MVP - Outlook]
external usenet poster
 
Posts: 1,885
Default Move email using the Close event



Vasil,

please see also my reply in the German newsgroup.

Additionally to the already mentioned issues:

For setting an object varibale you need to use the Set statement

Set myItem = ...

--
Best regards
Michael Bauer - MVP Outlook

: Outlook Categories? Category Manager Is Your Tool
: VBOffice Reporter for Data Analysis & Reporting
: http://www.vboffice.net/product.html?pub=6&lang=en


Am Wed, 22 Jul 2009 01:23:01 -0700 schrieb Vasil Vasilev:

Hi,

I made a custom form in Outlook 2003, which I assign to email messages in

a
certain subfolder of my inbox. Using this form, additional attributes can

be
assigned to the email. The user must open the mail, make the assignment,

save
it, and close it.
At this point I want to move this email to another folder. I'm using the
Close event, but I can't make it work...
I always get runtime error '-1040973560' (c1f40108)

Am I missing something?

Here my code:

Code:
 Public WithEvents myItem As Outlook.MailItem
 Dim myApp As New Outlook.Application
 
 
 Private Sub Application_Startup()
        Set myApp = CreateObject("Outlook.Application")
        Set myItem = myApp.ActiveInspector.CurrentItem
        ......
 End Sub
 
 
 Private Sub myItem_Close(Cancel As Boolean)
 
     Dim objNS As Outlook.NameSpace
     Set objNS = GetNamespace("MAPI")
     
     Dim destFolder As Object  'Outlook.MAPIFolder
     Set destFolder = 
 objNS.GetDefaultFolder(olFolderInbox).Folders("Processed")
     
     
     Set myItem = Application.ActiveInspector.CurrentItem
     
     If Not (myItem.MessageClass = "IPM.Note.PDV_Nachricht_de" Or _
               myItem.MessageClass = "IPM.Note.PDVA_Nachricht_de" ) Then
        MsgBox " Nothing happens"
     Else
             myItem.Move destFolder
     End If
     
 End Sub

P.S. I also tried to create a temporary mail item, make it equal to the
current mail item, move this one and delete the current... but still no

luck
Ads