Hi there, first post
I am trying to set up Outlook mail rules to move incoming mails into a folder based on certain keywords in the subject line.
The rules are being created in Access and passed across to Outlook - all works fine but I would like to be able to control the words to be searched for using a variable called "Keywords" rather than hard coding it.
For example, if the keywords being searched for are "Dog", "Cat", "Horse" then the following works (this is just part of the code so haven't posted the definitions of RuleIn, olRuleReceive, SubjectCondition etc):
This works:
However - I would like the .Text = Array element of the SubjectCondition to be driven by a string variable called Keywords, which can be compiled into any format and is currently equal to "Dog", "Cat", "Horse"
This does not work:
In Outlook I get a rule which looks for ""Dog", "Cat", "Horse"" (note double quotes at start and end - i.e. the rule looks for the whole string and not the individual values in the array.
Where am I going wrong?
I am trying to set up Outlook mail rules to move incoming mails into a folder based on certain keywords in the subject line.
The rules are being created in Access and passed across to Outlook - all works fine but I would like to be able to control the words to be searched for using a variable called "Keywords" rather than hard coding it.
For example, if the keywords being searched for are "Dog", "Cat", "Horse" then the following works (this is just part of the code so haven't posted the definitions of RuleIn, olRuleReceive, SubjectCondition etc):
This works:
Code:
Set RuleIn = colRules.Create("Inbox", olRuleReceive)
Set SubjectCondition = RuleIn.Conditions.BodyOrSubject
With SubjectCondition
.Enabled = True
.Text = Array("Dog", "Cat", "Horse")
End With
However - I would like the .Text = Array element of the SubjectCondition to be driven by a string variable called Keywords, which can be compiled into any format and is currently equal to "Dog", "Cat", "Horse"
This does not work:
Code:
Set RuleIn = colRules.Create("Inbox", olRuleReceive)
Set SubjectCondition = RuleIn.Conditions.BodyOrSubject
With SubjectCondition
.Enabled = True
.Text = Array(Keywords)
End With
In Outlook I get a rule which looks for ""Dog", "Cat", "Horse"" (note double quotes at start and end - i.e. the rule looks for the whole string and not the individual values in the array.
Where am I going wrong?