Link to home
Start Free TrialLog in
Avatar of jana
janaFlag for United States of America

asked on

Script VBA to assign a value to a user-define column in Outlook 2007 Inbox

We want to create a Rules Wizard so when an email that we received is from example@domain.com, the user-defined column 'Type' in the Outlook 2007 Inbox will have the value "SUPPORT"

The Rules Wizard part we have it, we are looking for the VBA portion that will save the value to the column
Avatar of Qlemo
Qlemo
Flag of Germany image

Private Sub SetTypeProperty(ByVal Item As MailItem)
  Call item.UserProperties.Add("Type", "SUPPORT")
End Sub

Open in new window

Avatar of jana

ASKER

We have worked with Rules Wizard and have created various, but not with script.

Hera is what we did: we placed your script within the MODULE in VBA but when creating the rules, it pops up a window 'Select Script' but is empty.

Please advice
SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jana

ASKER

Tried it, and gave an error "Run-rime error '13'" (see pic)
ErrorRules.jpg
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jana

ASKER

Hey buddy, dont say that! You guys in EE have been excellent with!!!

Will try & let you know

Thanx
Avatar of jana

ASKER

Didn't work.

Also tried "Run this rule now on messages already in Inbox" and it didn't work.

Avatar of jana

ASKER

We tested the Rules we created by changing it to assign a Category and it works.  But with the script it doesn't.  We place stop at "Sub SetTypeProperty(Item As MailItem)" to see it run line by line it does goes line by line but it doesn't fill the "Type" column.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jana

ASKER

Ok, tested it.  What I did was change the Type contents to "EE", then Alt-F11, CTRL-G and the "?..." and it does display the value I enter in the Type column.  I can change the value and run your test steps and it displays the changed contents.
Avatar of jana

ASKER

I placed the Item.Save and still no show
>> What I did was change the Type contents to "EE",
How did you do that?
Avatar of jana

ASKER

Ok What i did change the rule to sava SUPPORT In type column when the email received has TESTEE in the subject.

When sent, the rule didn't save SUPPORT in the type column; hence, Type is empty.  So I went in the Type column and change he value to "EE" (this is done by hanging the view to permit changes directly from user in inbox).  I can change the Type contents and user your yet steps and it does display the contents.
Avatar of jana

ASKER

I meant "when received my email, the rule didn't save SUPPORT in the type column"
So the value is changed successfully if you do it manually by any means, but not with the rule?
Avatar of jana

ASKER

The value is not changed.  What i mean is that the test instruction:

    "? Outlook.ActiveExplorer.Selection.Item(1).UserProperties("Type")"

Works after i manually change the "Type" contents.  The Rules worked perfectly because I see via the "Stop" that the control does go thru the VBA lines.  However, the value "SUPPORT" doesn't get saved in the received email.

I place Item.Save right before the END, is that correct?
Yes. Let me test again, with the complete workflow needed. Maybe I have overlooked something.
Works fine for me. I added the User Column Type to my view in OL2010, created a rule triggering the VBA code
Sub SetTypeProperty(Item As MailItem)
  Item.UserProperties.Add("Type", olText) = "SUPPORT"
  Item.Save
End Sub

Open in new window

and see the Type column filled with SUPPORT in my view. OL2007 or OL2010 do not differ in that regard (and OL2003 works the same, too).
Avatar of jana

ASKER

Strange ... it doesn't on mine& its ol2007.  But will review on detail when back office.
Make sure you are really seeing the User Property, not any other field called "Type". It might be part of a customized form, and hence need to be addressed differently.
Avatar of jana

ASKER

It worked!! But I didn't nothin different.  Let me check again.
Avatar of jana

ASKER

Thanx