Solved

How can I get the value of a User-Define column in Outlook Inbox where the columna name has to name

Posted on 2012-04-09
17
615 Views
Last Modified: 2012-04-10
In Outlook 2007, in VBA, we access all the InBox column names or fields; including User-Defined fields.  We have had no problem with it until one of the User-Defined was compose of 2 words, for example "Comments & Obs".  

How can we access User-Defined that have spaces within their Fileds names?
0
Comment
Question by:rayluvs
  • 9
  • 5
  • 3
17 Comments
 

Author Comment

by:rayluvs
ID: 37825243
Note:
The current way we access the InBox fields are as follow:

- for standard email columns: itm.Categories
- for User-Defined columns: itm.UserProperties("Project")

However, some time back, we included a new User-Defined columns in InBox thet the name has spaced in:  "Comments & Obs"

However, when accessing it with the current format of itm.UserProperties("Comments & Obs"), we get the following error:


---------------------------
Microsoft Visual Basic
---------------------------
Run-time error '91':

Object variable or With block variable not set
---------------------------
OK   Help  
---------------------------
0
 

Author Comment

by:rayluvs
ID: 37825401
Just discovered a very curious thing.  The error message appears if the InBox Column values is empty.  We troubleshoot it and came this conclusion.

It always happen when the Column value is being passed to a variable string:

vTasks = itm.UserProperties("Task")

If vTasks = itm.UserProperties("Task") has data, the value is set to vTasks.  If the value is empty, it displays the error message Run-time error '91'.

Please advice
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 37825453
You should make sure to have the user property set, even if empty, on each item. If uncertain I explicitely add the property before asking for its value:
  call itm.UserProperties.Add("Task", olText)

Am I correct that your issue is only related to the empty / non-existent user property, or is the "Comments & Obs" name still causing trouble?
0
 

Author Comment

by:rayluvs
ID: 37825515
It's related to empty / non-existent user property.  Tested on both types.

Will try suggesttion
0
 

Author Comment

by:rayluvs
ID: 37825523
Modified line to:  

vTasks =  itm.UserProperties.Add("Task", olText)

Didn't' work.
0
 

Author Comment

by:rayluvs
ID: 37825537
Actually, gave a different error message:

UserDefError
0
 

Author Comment

by:rayluvs
ID: 37825588
Still testing here and noticed that the problem is not when passing data, but the column itself.  We can't even validate its contents, like so:


if itm.UserProperties("Task") > " " then...

Please advice
0
 
LVL 68

Accepted Solution

by:
Qlemo earned 500 total points
ID: 37825596
You will need two lines:
  call itm.UserProperties.Add("Task", olText)
  vTasks = itm.UserProperties("Task")

Open in new window

The first line will add the property, if it does not exist yet.
The second line will independently ask for the value. The important point is that you call the Add method before you access the property.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:rayluvs
ID: 37825617
Thank you very Much!!!!!

Worked Excellently!

So to conclude, if we want to read a user-defined column without the errors reported at top, we must include the "call" (with the user-defin column name) prior doing anything with it?
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 37825653
At least if you cannot be sure the property is already there.
Another way is, of course to use on error resume next, but that is dangerous, as you can easily oversee other errors.
0
 

Author Comment

by:rayluvs
ID: 37825717
ok
0
 
LVL 13

Expert Comment

by:Chris Raisin
ID: 37826011
That answer is not totally correct, since I think you will find that if the property "Task" has a value, an error will occur.

The answer is a "get around" if there is no task there.

The correct coding should be found in what I have already given you:

  For nItem = 1 To itm.UserProperties.Count
      Select Case LCase(itm.UserProperties.Item(nItem).Name)
        Case "project"
          vProject = itm.UserProperties.Item(nItem).value
        Case "tasks"
          vTasks = itm.UserProperties.Item(nItem).value
        Case "type"
          vType = itm.UserProperties.Item(nItem).value
      End Select
    Next

Open in new window


What the solution you have accepted does is simply add a blank "task" to an item and then return that blank value, so it is not really needed.

vTasks will always contain an empty string if there are no tasks in your email item and so running the code I have already given you should ensure this error do not happen.

Cheers
Chris
0
 

Author Comment

by:rayluvs
ID: 37826025
Just the coding but didn't see it.  Unless, it was in one of those fragments of coding; will check
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 37826711
craisin,

There is a big difference between both suggestions. This question was about a particular user property, not about dynamically checking for existing ones. And you are not correct stating
What the solution you have accepted does is simply add a blank "task" to an item and then return that blank value, so it is not really needed.
because it adds a blank user property only if does not exist yet. Accessing a non-existent user property results in the error message "Object variable or With block variable not set". Further,
That answer is not totally correct, since I think you will find that if the property "Task" has a value, an error will occur.
is also false - why should querying the value of an existing property result in an error? And the .Add method doesn't do anything if the property already exists (not even error out).
From the (very restricted) case presented by the Asker here my solution is correct, and what you post is far beyond the scope of this question. It is nevertheless correct if you need a much more flexible handling of a varying set of user properties.
0
 
LVL 13

Expert Comment

by:Chris Raisin
ID: 37829572
Point taken.  :-)

The original question was on user-defined fields which have spaces in their names, so I will look into that now.

I have been working extensively on this project with the author and most of the code the user is running is code I have supplied (I think).

Thanks for your clarification Qlemo

Cheers
Chris
0
 
LVL 13

Expert Comment

by:Chris Raisin
ID: 37829592
Have you tried:


        vComments = itm.UserProperties.Item("Comments & Obs").value

where you access the actual value rather than the default setting for the item?
(It may have a problem there is there is a space in the items name)

Cheers
Chris
0
 
LVL 68

Expert Comment

by:Qlemo
ID: 37830255
Chris,

This question morphed from "issue with property containing spaces" to "non-existent property results in error", see http:#a37825515. Confusing, but true.

I understand well that you might have the insight into the big picture, and the answer you presented could be the best fitting under that circumstances. But if the Asker considers the issue as resolved, we should leave it at that now.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Find out how to use dynamic social media in email signatures with this top 10 DOs & DON’Ts.
Get an idea of what you should include in an email disclaimer with these Top 5 email disclaimer tips.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now