Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Go Back   Code Forums > Application and Web Development > Visual Basic 6
User Name
Password

Reply
 
LinkBack Thread Tools Display Modes
Old 11-24-2003, 02:17 AM   #1 (permalink)
gicio
Registered User
 
Join Date: Dec 2002
Posts: 12
gicio is on a distinguished road
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
__________________
gicio is offline   Reply With Quote
Old 11-25-2003, 05:16 AM   #2 (permalink)
Hrqls
Regular Contributor
 
Join Date: May 2002
Location: Alkmaar, the Netherlands
Posts: 167
Hrqls is on a distinguished road
i never used vba in outlook .. but maybe the items in the mapifolder arent all mailitems .. maybe there are some subfolders as well ?

have a look at the items which your loop encounters .. if there is a 'item' which is in fact a folder .. then you have to loop through that out as well
(you could do this recursively)
__________________
The specialty of the house? thats me (cheap as always)
Hrqls is offline   Reply With Quote
Reply


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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
An Introduction to XHTML/CSS Rie HTML / CSS 0 03-07-2003 06:50 PM


All times are GMT -8. The time now is 09:57 PM.


Powered by vBulletin Version 3.6.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle