Solved

run outlook Rule from access 2010 vba code then delete all rules

Posted on 2016-09-19
2
64 Views
Last Modified: 2016-09-19
I have that creates a rule in outlook from access vba code.
Internet code.

It creates the rule then saves it.
Works great.

What I need:
I now need to execute that same rule...then delete the RULE.

I need to RUN THE RULE from the "Sent Items"  folder specifically.


Code for Creating the rule:
Dim colStores As Outlook.Stores
Dim oStore As Outlook.Store
Dim oFolders As Outlook.Folders
Dim oInbox As Outlook.folder
Dim Folder_Name As String
Dim Rname As String

Folder_Name = SELLER_NAME & "_" & "EscalationId_" & price_escNum & "_Created_" & Date
Rname = "Action Required - Pricing Escalation" & " #'" & price_escNum & "'"
'  On Error Resume Next

Set colStores = Outlook.Session.Stores
Set oFolders = colStores.Item("bookprice@xxxxxx.com").GetDefaultFolder(olFolderInbox).Folders.Item("Archive").Folders
oFolders.Add (Folder_Name)
   
Dim colRules As Outlook.Rules
   Dim oRule As Outlook.Rule
   Dim colRuleActions As Outlook.RuleActions
   Dim oRuleAction As Outlook.RuleAction
   Dim oMoveRuleAction As Outlook.MoveOrCopyRuleAction
   Dim oFromCondition As Outlook.ToOrFromRuleCondition
   Dim oSubjectCondition As Outlook.TextRuleCondition
   Dim oExceptSubject As Outlook.TextRuleCondition
   
   Dim oMoveTarget As Outlook.folder
   On Error Resume Next
   'Specify target folder for rule move action
   Set oInbox = Outlook.Session.Stores.Item("bookprice@xxxxxx.com").GetDefaultFolder(olFolderInbox).Folders.Item("Archive")
   'Debug.Print oInbox.FolderPath
   'Assume that target folder already exists
   Set oMoveTarget = oInbox.Folders(Folder_Name)
   'Get Rules from Session.DefaultStore object
   Set colRules = Outlook.Session.Stores.Item("bookprice@xxxxxx.com").GetRules()
   'Create the rule by adding a Receive Rule to Rules collection
   Set oRule = colRules.Create(Rname, olRuleReceive)
   'Specify the condition in a ToOrFromRuleCondition object
   'Condition is if the message is sent by "DanWilson"
   Set oSubjectCondition = oRule.Conditions.Subject
   With oSubjectCondition
      .Enabled = True
      .Text = Array(Rname)
   End With
   'Specify the action in a MoveOrCopyRuleAction object
   'Action is to move the message to the target folder
   Set oMoveRuleAction = oRule.Actions.MoveToFolder
   With oMoveRuleAction
      .Enabled = True
      .folder = oMoveTarget
   End With
   'Set rule to stop processing more rules
   Set oRuleAction = oRule.Actions.Stop
   With oRuleAction
      .Enabled = True
   End With
   'Update the server and display progress dialog
   colRules.Save

Open in new window

0
Comment
Question by:fordraiders
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 500 total points
ID: 41805134
Just as a side comment, seems to me you'd be better off just processing the items in the folder and do what the rule does via code and forget about rules entirely.  I don't have time to dig into this with you, but it seems like your heading in the wrong direction.

Jim.
0
 
LVL 3

Author Closing Comment

by:fordraiders
ID: 41805160
thanks
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question