Method 'Categories" failed with object 'DocumentItem'

  • Thread starter Thread starter Lorenz H?lscher
  • Start date Start date
L

Lorenz H?lscher

Hi everyone,

with Word-VBA I made an addin that lists Outlook/Exchange-eMails resp.
their attachments (which I need to import if they are newer than local
files). This works for 2 years on about 1000 customer pc's. But
sometimes there is a strange error message saying something like
"Error -2147417851: Method 'Categories" failed with object
'DocumentItem'".

What does this mean and why does it approach?

Thanks in advance,
Lorenz
 
Lorenz:

See this article about how to translate error messages:

http://support.microsoft.com/default.aspx?scid=kb;
[LN];Q186063

In this case, I looked it up for you. Here is what I found:

<<
//
// MessageId: RPC_E_SERVERFAULT
//
// MessageText:
//
// The server threw an exception.
//
#define RPC_E_SERVERFAULT _HRESULT_TYPEDEF_
(0x80010105L)
WHY Outlook (the server in this case) threw the exception,
I couldn't tell you without seeing some of your code. Have
you ever run the code in Debug mode and experienced the
error? That at least would tell you WHERE in your code the
error occurred. Alternately, you could pepper your code
with MsgBox or (if in Debug mode) Debug.Print statements
after every major operation. Again, that would give you an
idea of where the problem is occurring.

Without more information, I can't help.

-Andrew
==============================
 
Hi Andrew,

the ".Categories" property has been called only once so it's quite
easy to find this part of the code. As you see I have to use late
binding because of too much Outlook versions and even some users not
having Outlook at all.

First there is a general sub to have Outlook opened and (from a user
form) there is the part of the code below the sub to check the
categories of every item in that given folder:
********************************************
Dim OLApp As Object 'Outlook.Application
Dim OLNS As Object 'Outlook.NameSpace
Dim OLItem As Object 'Outlook.DocumentItem



Sub OutlookOeffnen()
On Error Resume Next
Set OLApp = CreateObject("Outlook.Application")
Set OLNS = OLApp.GetNamespace("MAPI")
If Err.Number > 0 Then
MsgBox "Couldn't open Outlook/Exchange. Fehler Nr. " & _
Err.Number & ":" & vbCrLf & Err.Description, vbCritical
Err.Clear
Exit Sub
End If
End Sub



[...]

Set OLOrdner = OLNS.Folders(edtGruppe.Value).Folders(edtOrdnerOL1.Value).
_
Folders(edtOrdnerOL2.Value).Folders(edtOrdnerOL3.Value)

[...]

If Not OLOrdner Is Nothing Then
If OLOrdner.Items.Count = 0 Then
MsgBox "Outlook folder '" & OLOrdner.Name & "' does not
contain files!"
Exit Sub
End If

For Each OLItem In OLOrdner.Items
tmp = OLItem.categories

***********************************************

The last row is the one with the problem. Is it "allowed" for a
contact item not to have categories at all?

Unfortunately this happens sometimes only and with a customer's pc far
away. That is why I can't put him aside and watch debug code running.
Maybe it's an Exchange problem only because I never saw it when using
my own Outlook?

bye, Lorenz
 
Lorenz-

First, yes, it is perfectly fine for a contact item not to
have any Categories attached at all. But you might run
into a problem if you try to assign an empty string as a
Category.

Next, a couple questions occur: I don't see where the
value of the "tmp" variable is coming from. Are you
checking to make sure it is a string, and not empty,
before you assing it to OLItem.Categories?

Next, are you checking each Item in the collection to make
sure it is, in fact, a ContactItem? That one tripped me up
once. You see, in addition to actual Contacts, many
Contacts folders include Distribution Lists and/or Groups.
Either of those will trip up your code as it is now.

In fact, I would guess that this is the root of your
problem. Try code like this:

If OLItem.Class = olContact Then
'continue
Else
' go on to next item
End If

Hope that helps,

-Andrew
====================================
-----Original Message-----
Hi Andrew,

the ".Categories" property has been called only once so it's quite
easy to find this part of the code. As you see I have to use late
binding because of too much Outlook versions and even some users not
having Outlook at all.

First there is a general sub to have Outlook opened and (from a user
form) there is the part of the code below the sub to check the
categories of every item in that given folder:
********************************************
Dim OLApp As Object 'Outlook.Application
Dim OLNS As Object 'Outlook.NameSpace
Dim OLItem As Object 'Outlook.DocumentItem



Sub OutlookOeffnen()
On Error Resume Next
Set OLApp = CreateObject("Outlook.Application")
Set OLNS = OLApp.GetNamespace("MAPI")
If Err.Number > 0 Then
MsgBox "Couldn't open Outlook/Exchange. Fehler Nr. " & _
Err.Number & ":" & vbCrLf & Err.Description, vbCritical
Err.Clear
Exit Sub
End If
End Sub



[...]

Set OLOrdner = OLNS.Folders(edtGruppe.Value).Folders (edtOrdnerOL1.Value).
_
Folders(edtOrdnerOL2.Value).Folders
(edtOrdnerOL3.Value)

[...]

If Not OLOrdner Is Nothing Then
If OLOrdner.Items.Count = 0 Then
MsgBox "Outlook folder '" & OLOrdner.Name & "' does not
contain files!"
Exit Sub
End If

For Each OLItem In OLOrdner.Items
tmp = OLItem.categories

***********************************************

The last row is the one with the problem. Is it "allowed" for a
contact item not to have categories at all?

Unfortunately this happens sometimes only and with a customer's pc far
away. That is why I can't put him aside and watch debug code running.
Maybe it's an Exchange problem only because I never saw it when using
my own Outlook?

bye, Lorenz
.
 
Hi Andrew,

Andrew Cushen said:
First, yes, it is perfectly fine for a contact item not to
have any Categories attached at all. But you might run
into a problem if you try to assign an empty string as a
Category.
Good to know. I can check them manually before because it is either
one of two public folders.
Next, a couple questions occur: I don't see where the
value of the "tmp" variable is coming from. Are you
checking to make sure it is a string, and not empty,
before you assing it to OLItem.Categories?
Ooops, do we see the same code?
************************
For Each OLItem In OLOrdner.Items
tmp = OLItem.categories
************************
Ok, I don't really check whether it's a string type but I don't assign
it to OLItem.Categories. I see the opposite: the value is coming from
OLItem.Categories and not assigned to! Or am I wrong??
Next, are you checking each Item in the collection to make
sure it is, in fact, a ContactItem? That one tripped me up
once. You see, in addition to actual Contacts, many
Contacts folders include Distribution Lists and/or Groups.
Either of those will trip up your code as it is now.
I will ensure this. But in this special case there are only two public
folders allowed to use so I'm quite sure that each of the items is a
ContactItem and not a Distribution List. But maybe someone inserted
something wrong by accident inbetween.
In fact, I would guess that this is the root of your
problem. Try code like this:
If OLItem.Class = olContact Then
'continue
Else
' go on to next item
End If

Hope that helps,
Yes, it does, thanks!
Lorenz
 
Back
Top