• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 676
  • Last Modified:

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

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
rayluvs
Asked:
rayluvs
  • 9
  • 5
  • 3
1 Solution
 
rayluvsAuthor Commented:
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
 
rayluvsAuthor Commented:
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
 
QlemoC++ DeveloperCommented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
rayluvsAuthor Commented:
It's related to empty / non-existent user property.  Tested on both types.

Will try suggesttion
0
 
rayluvsAuthor Commented:
Modified line to:  

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

Didn't' work.
0
 
rayluvsAuthor Commented:
Actually, gave a different error message:

UserDefError
0
 
rayluvsAuthor Commented:
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
 
QlemoC++ DeveloperCommented:
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
 
rayluvsAuthor Commented:
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
 
QlemoC++ DeveloperCommented:
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
 
rayluvsAuthor Commented:
ok
0
 
Chris Raisin(Retired Analyst/Programmer)Commented:
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
 
rayluvsAuthor Commented:
Just the coding but didn't see it.  Unless, it was in one of those fragments of coding; will check
0
 
QlemoC++ DeveloperCommented:
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
 
Chris Raisin(Retired Analyst/Programmer)Commented:
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
 
Chris Raisin(Retired Analyst/Programmer)Commented:
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
 
QlemoC++ DeveloperCommented:
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

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 9
  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now