Current location: Hot Scripts Forums » Programming Languages » Visual Basic » VBA: My Outlook VBA rule code does't work :(


VBA: My Outlook VBA rule code does't work :(

Reply
  #1 (permalink)  
Old 11-24-03, 05:31 AM
gicio gicio is offline
Newbie Coder
 
Join Date: Sep 2003
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Question VBA: My Outlook VBA rule code does't work :(

Hi!!!

I write some VBA code that doesn't work good.
what the code SHOULD do:

After the send/receive proces the code loop through all messages in the inbox
and move the messages in the right folders (depend on the sender email address).

the problem is that after 3 loops I got a :

Run-time error '13': Type mismatch.


can someone tell me why I get this error?






Code:
Option Explicit


    Private Sub Application_NewMail()
        Dim currentNameSpace As NameSpace
        Dim currentMAPIFolder As MAPIFolder
        Dim currentMailItem As MailItem

        Set currentNameSpace = Application.GetNamespace("MAPI")
        Set currentMAPIFolder = currentNameSpace.GetDefaultFolder(olFolderInbox)

        For Each currentMailItem In currentMAPIFolder.Items

            'GotDotNet_Community@ microsoft.com
            If currentMailItem.SenderEmailAddress = "GotDotNet_Community@microsoft.com" Then
                Call MoveMail(currentMailItem, currentMAPIFolder.Folders.Item("Forum").Folders.Item("GotDotNet").EntryID)
            'newsalerts-noreply@google.com
            ElseIf currentMailItem.SenderEmailAddress = "newsalerts-noreply@google.com" Then
                Call MoveMail(currentMailItem, currentMAPIFolder.Folders.Item("News").Folders.Item("Google.com").EntryID)
            'newsmail@derStandard.at
            ElseIf currentMailItem.SenderEmailAddress = "newsmail@derStandard.at" Then
                Call MoveMail(currentMailItem, currentMAPIFolder.Folders.Item("Newsletter").Folders.Item("DerStandard.at").EntryID)

            Else

            End If

        Next currentMailItem

        Set currentMAPIFolder = Nothing
        Set currentNameSpace = Nothing
    End Sub


    Private Function MoveMail(currentMailItem As MailItem, strTargFldrID As String) As Boolean
        Dim currentNameSpace As NameSpace
        Dim currentMoveMailItem As MailItem

        Set currentNameSpace = Application.GetNamespace("MAPI")

        On Error GoTo FINISH:
        Set currentMoveMailItem = currentMailItem.Copy
        currentMoveMailItem.Move Destfldr:=currentNameSpace.GetFolderFromID(strTargFldrID)
        currentMailItem.Delete
FINISH:
        MoveMail = CBool(Err.Number)
    End Function
Reply With Quote
  #2 (permalink)  
Old 12-03-03, 10:21 AM
Emmanuel Emmanuel is offline
Newbie Coder
 
Join Date: Dec 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
There is something other than mail object...

Hi,

Check all content of your Inbox. If there is an item different from a mail object this error is generated : Do you use read confirmation option when use send a mail to someone ?
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
The Art Nexus seeking PHP programmers TheArtNexus Job Offers & Assistance 5 02-26-08 03:08 AM


All times are GMT -5. The time now is 01:17 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.