Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 24th, 2003, 05:27 AM
gicio gicio is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Posts: 90 gicio User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m 30 sec
Reputation Power: 6
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  
Old November 25th, 2003, 02:51 PM
NicMic's Avatar
NicMic NicMic is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Cheltenham, England.
Posts: 96 NicMic User rank is Corporal (100 - 500 Reputation Level)NicMic User rank is Corporal (100 - 500 Reputation Level)NicMic User rank is Corporal (100 - 500 Reputation Level)NicMic User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 44 m 59 sec
Reputation Power: 9
Run it with F8 (line-by-line step-through) to see where the error is occuring (perhaps disable "ON ERROR") then repost with the info.

Reply With Quote
  #3  
Old November 25th, 2003, 08:36 PM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
Can u debug your program with step-through,and u will find where the wrong happened!U can give us the wrong in which line..

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > VBA: My Outlook VBA rule code does't work :(


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT