Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
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
Medium Priority
?
671 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
[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
  • 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 71

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
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 

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 71

Accepted Solution

by:
Qlemo earned 2000 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
 

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 71

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 71

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 71

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

This article describes how to import an Outlook PST file to Office 365 using a third party product to avoid Microsoft's Azure command line tool, saving you time.
Are you looking for the options available for exporting EDB files to PST? You may be confused as they are different in different Exchange versions. Here, I will discuss some options available.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…

618 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