Outlook Contacts in Excell or Access

S

Sue Mosher [MVP]

Did you add a reference to CDO 1.21 to your project? You can't use CDO
constants in your code until you do.

Also, I don't see that you're instantiating objSession anywhere. This is the
minimum if you want it to use the same session that Outlook is already
running under:

Set objSession = CreateObject("MAPI.Session")
objSession.Logon "", "", False, False
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
J

John Galt

Yes I did add CDO 1.21.
I am now getting a type mismatch on the same statement.
It does not like cdoDefaultfolderscontacts or a numeric constant of 5 or
"Contacts".
I do not understand why this is failing.
 
S

Sue Mosher [MVP]

Comments inline.
The data stamp on my CDO.DLL is 3/17/2002 3:29PM.
Is this the latest dll?

Sounds right. What's the path?
Probably because you declared objFolder as CDO.Folder, not MAPI.Folder. Make
sure you get the right declaration for each variable.
 
J

John Galt

I actually have this working (Well almost).
The original problem was to expose 3 particular fields in the contacts
folder:
1. Reminder time
2. Flag Status
3. Followup Flag

I use the CDO representations for these 3 fields:

1. CdoPR_FLAG_DUE_BY
2. CdoPR_FLAG_STATUS
3. CdoPR_ACTION_DATE

I still cannot get these variables. I get Run-time error '-2147221233
(8004010f'):
[Collaboration Data Objects - [MAPI_E_NOT_FOUND(8004010F)]]

Any pointers ???

Thanks
 
S

Sue Mosher [MVP]

Code snippet?

John Galt said:
I actually have this working (Well almost).
The original problem was to expose 3 particular fields in the contacts
folder:
1. Reminder time
2. Flag Status
3. Followup Flag

I use the CDO representations for these 3 fields:

1. CdoPR_FLAG_DUE_BY
2. CdoPR_FLAG_STATUS
3. CdoPR_ACTION_DATE

I still cannot get these variables. I get Run-time error '-2147221233
(8004010f'):
[Collaboration Data Objects - [MAPI_E_NOT_FOUND(8004010F)]]

Any pointers ???

Thanks

John Galt said:
They data stamp on my CDO.DLL is 3/17/2002 3:29PM.
Is this the latest dll?
This
is or
with
folder
part
of CDO
1.21
seem
 
J

John Galt

Here is the code so far.


Private Sub cmdTEST_CLick()
Dim objSession As MAPI.Session
Dim objFolder As MAPI.Folder
Dim objmessages As MAPI.Messages
Dim objFields As MAPI.Fields
Dim objmessage As MAPI.Message


Set objSession = CreateObject("MAPI.Session")
If Not objSession Is Nothing Then
strProfileName = "MS Exchange Settings"
objSession.Logon strProfileName, , False
End If

Set objFolder = objSession.GetDefaultFolder(CdoDefaultFolderContacts)
Set objFolder =
objSession.GetFolder("00000000515BA5871FC8D5119923000475762650C2960000")
'GetFolder("My Local E-Mail\Morang Cove Trading Company\MCTC Contacts")
' Get the first message of the contacts folder
' Note that it is still a message object
' So the class property will always return a value of CdoMsg
Set objmessages = objFolder.Messages
Set objmessage = objmessages.GetFirst()

' Get the fields collection of the contact item
'Set objFields = objmessage.Fields

' Get a single field using the MAPI property tag
Set ObjField = objFields.Item(1)

' For Example:
Set ObjField = objFields.Item(&H3001001E)
x = 0
On Error Resume Next

For I = 1 To objmessages.Count
Set objmessage = objmessages.GetNext()
Set objFields = objmessage.Fields
For x = 1 To 1000
If InStr(objmessage.Field("Categories"), "Buyer") > 0 Then
Debug.Print "x = " & x & " " & objFields(x)
End If
Next x
Next I

'*** Code to review *************
' If it is a Microsoft Outlook item you can either use
Set ObjField = objFields.Item("<PropertyTag>", "<PropertySetID>")

' For Example:
Set ObjField = objFields.Item("0x8013", "0820060000000000C000000000000046")

' Or the following syntax if you want to read the value directly
Value = objFields.Item("{" & "<PropertySetID>" & "}" &
"<PropertyTag>").Value

' For Example:
Value = objFields.Item("{0820060000000000C000000000000046}0x8535").Value

' If it is a Microsoft Outlook item with a custom field use the following
syntax:
Set ObjField = objFields.Item("<NameOfUserdefinedField>")

' For Example:
Set ObjField = objFields.Item("PersonRole")

End Sub





Sue Mosher said:
Code snippet?

John Galt said:
I actually have this working (Well almost).
The original problem was to expose 3 particular fields in the contacts
folder:
1. Reminder time
2. Flag Status
3. Followup Flag

I use the CDO representations for these 3 fields:

1. CdoPR_FLAG_DUE_BY
2. CdoPR_FLAG_STATUS
3. CdoPR_ACTION_DATE

I still cannot get these variables. I get Run-time error '-2147221233
(8004010f'):
[Collaboration Data Objects - [MAPI_E_NOT_FOUND(8004010F)]]

Any pointers ???

Thanks

John Galt said:
They data stamp on my CDO.DLL is 3/17/2002 3:29PM.
Is this the latest dll?


Yes I did add CDO 1.21.
I am now getting a type mismatch on the same statement.
It does not like cdoDefaultfolderscontacts or a numeric constant of
5
or This folder part dim
the
CDO
for
a seem them
as
 
S

Sue Mosher [MVP]

But which statement is giving you the runtime error?

Don't forget that you have to check for the existence of the field first,
before accessing its value, since CDO only stores fields in the Fields
collection if they have values.

John Galt said:
Here is the code so far.


Private Sub cmdTEST_CLick()
Dim objSession As MAPI.Session
Dim objFolder As MAPI.Folder
Dim objmessages As MAPI.Messages
Dim objFields As MAPI.Fields
Dim objmessage As MAPI.Message


Set objSession = CreateObject("MAPI.Session")
If Not objSession Is Nothing Then
strProfileName = "MS Exchange Settings"
objSession.Logon strProfileName, , False
End If

Set objFolder = objSession.GetDefaultFolder(CdoDefaultFolderContacts)
Set objFolder =
objSession.GetFolder("00000000515BA5871FC8D5119923000475762650C2960000")
'GetFolder("My Local E-Mail\Morang Cove Trading Company\MCTC Contacts")
' Get the first message of the contacts folder
' Note that it is still a message object
' So the class property will always return a value of CdoMsg
Set objmessages = objFolder.Messages
Set objmessage = objmessages.GetFirst()

' Get the fields collection of the contact item
'Set objFields = objmessage.Fields

' Get a single field using the MAPI property tag
Set ObjField = objFields.Item(1)

' For Example:
Set ObjField = objFields.Item(&H3001001E)
x = 0
On Error Resume Next

For I = 1 To objmessages.Count
Set objmessage = objmessages.GetNext()
Set objFields = objmessage.Fields
For x = 1 To 1000
If InStr(objmessage.Field("Categories"), "Buyer") > 0 Then
Debug.Print "x = " & x & " " & objFields(x)
End If
Next x
Next I

'*** Code to review *************
' If it is a Microsoft Outlook item you can either use
Set ObjField = objFields.Item("<PropertyTag>", "<PropertySetID>")

' For Example:
Set ObjField = objFields.Item("0x8013", "0820060000000000C000000000000046")

' Or the following syntax if you want to read the value directly
Value = objFields.Item("{" & "<PropertySetID>" & "}" &
"<PropertyTag>").Value

' For Example:
Value = objFields.Item("{0820060000000000C000000000000046}0x8535").Value

' If it is a Microsoft Outlook item with a custom field use the following
syntax:
Set ObjField = objFields.Item("<NameOfUserdefinedField>")

' For Example:
Set ObjField = objFields.Item("PersonRole")

End Sub





Sue Mosher said:
Code snippet?

John Galt said:
I actually have this working (Well almost).
The original problem was to expose 3 particular fields in the contacts
folder:
1. Reminder time
2. Flag Status
3. Followup Flag

I use the CDO representations for these 3 fields:

1. CdoPR_FLAG_DUE_BY
2. CdoPR_FLAG_STATUS
3. CdoPR_ACTION_DATE

I still cannot get these variables. I get Run-time error '-2147221233
(8004010f'):
[Collaboration Data Objects - [MAPI_E_NOT_FOUND(8004010F)]]

Any pointers ???

Thanks

They data stamp on my CDO.DLL is 3/17/2002 3:29PM.
Is this the latest dll?


Yes I did add CDO 1.21.
I am now getting a type mismatch on the same statement.
It does not like cdoDefaultfolderscontacts or a numeric constant
of
5 use
CDO Variable
or the
CDO http://www.slipstick.com/dev/cdo.htm
if CDO for
 
J

John Galt

In the following statement when I use any of the 3 cdoVariables or the
Property Tag

i.e. Set ObjField = objFields.Item(&H10820040)
Set ObjField = objFields.Item(CdoPR_ACTION_DATE)



Sue Mosher said:
But which statement is giving you the runtime error?

Don't forget that you have to check for the existence of the field first,
before accessing its value, since CDO only stores fields in the Fields
collection if they have values.

John Galt said:
Here is the code so far.


Private Sub cmdTEST_CLick()
Dim objSession As MAPI.Session
Dim objFolder As MAPI.Folder
Dim objmessages As MAPI.Messages
Dim objFields As MAPI.Fields
Dim objmessage As MAPI.Message


Set objSession = CreateObject("MAPI.Session")
If Not objSession Is Nothing Then
strProfileName = "MS Exchange Settings"
objSession.Logon strProfileName, , False
End If

Set objFolder = objSession.GetDefaultFolder(CdoDefaultFolderContacts)
Set objFolder =
objSession.GetFolder("00000000515BA5871FC8D5119923000475762650C2960000")
'GetFolder("My Local E-Mail\Morang Cove Trading Company\MCTC Contacts")
' Get the first message of the contacts folder
' Note that it is still a message object
' So the class property will always return a value of CdoMsg
Set objmessages = objFolder.Messages
Set objmessage = objmessages.GetFirst()

' Get the fields collection of the contact item
'Set objFields = objmessage.Fields

' Get a single field using the MAPI property tag
Set ObjField = objFields.Item(1)

' For Example:
Set ObjField = objFields.Item(&H3001001E)
x = 0
On Error Resume Next

For I = 1 To objmessages.Count
Set objmessage = objmessages.GetNext()
Set objFields = objmessage.Fields
For x = 1 To 1000
If InStr(objmessage.Field("Categories"), "Buyer") > 0 Then
Debug.Print "x = " & x & " " & objFields(x)
End If
Next x
Next I

'*** Code to review *************
' If it is a Microsoft Outlook item you can either use
Set ObjField = objFields.Item("<PropertyTag>", "<PropertySetID>")

' For Example:
Set ObjField = objFields.Item("0x8013", "0820060000000000C000000000000046")

' Or the following syntax if you want to read the value directly
Value = objFields.Item("{" & "<PropertySetID>" & "}" &
"<PropertyTag>").Value

' For Example:
Value = objFields.Item("{0820060000000000C000000000000046}0x8535").Value

' If it is a Microsoft Outlook item with a custom field use the following
syntax:
Set ObjField = objFields.Item("<NameOfUserdefinedField>")

' For Example:
Set ObjField = objFields.Item("PersonRole")

End Sub





Sue Mosher said:
Code snippet?

I actually have this working (Well almost).
The original problem was to expose 3 particular fields in the contacts
folder:
1. Reminder time
2. Flag Status
3. Followup Flag

I use the CDO representations for these 3 fields:

1. CdoPR_FLAG_DUE_BY
2. CdoPR_FLAG_STATUS
3. CdoPR_ACTION_DATE

I still cannot get these variables. I get Run-time error '-2147221233
(8004010f'):
[Collaboration Data Objects - [MAPI_E_NOT_FOUND(8004010F)]]

Any pointers ???

Thanks

They data stamp on my CDO.DLL is 3/17/2002 3:29PM.
Is this the latest dll?


Yes I did add CDO 1.21.
I am now getting a type mismatch on the same statement.
It does not like cdoDefaultfolderscontacts or a numeric constant
of
5
or
"Contacts".
I do not understand why this is failing.


Did you add a reference to CDO 1.21 to your project? You can't use
CDO
constants in your code until you do.

Also, I don't see that you're instantiating objSession anywhere.
This
is
the
minimum if you want it to use the same session that Outlook is
already
running under:

Set objSession = CreateObject("MAPI.Session")
objSession.Logon "", "", False, False
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



I reran now and have CDO.DLL!
I now Have MAPI.Session working.

The next part of the code that the sample shows is
Set objFolder =
objSession.GetDefaultFolder(CdoDefaultFolderContacts)

When I hit this statement in the debugger I get "Object Variable
or
with
block not set.


Here is my code taken from the example:

Private Sub cmdTEST_CLick()
Dim objSession As MAPI.Session
Dim objFolder As CDO.Folder
'Set objSession = oOutlook.CdoNamespace ' Get the contacts
folder
of
the
mailbox
Set objFolder =
objSession.GetDefaultFolder(CdoDefaultFolderContacts)
' Get the first message of the contacts folder
' Note that it is still a message object
' So the class property will always return a value of CdoMsg
'Set objMessages = objFolder.Messages
'Set objMessage = objMessages.GetFirst()

' Get the fields collection of the contact item
Set objFields = objMessage.Fields

' Get a single field using the MAPI property tag
Set objField = objFields.Item(PR_DISPLAY_NAME)

' For Example:
Set objField = objFields.Item(&H3001001E)

' If it is a Microsoft Outlook item you can either use
Set objField = objFields.Item("<PropertyTag>",
' For Example:
Set objField = objFields.Item("0x8535",
"0820060000000000C000000000000046")

' Or the following syntax if you want to read the value directly
Value = objFields.Item("{" & "<PropertySetID>" & "}" &
"<PropertyTag>").Value

' For Example:
Value =
objFields.Item("{0820060000000000C000000000000046}0x8535").Value

' If it is a Microsoft Outlook item with a custom field use the
following
syntax:
Set objField = objFields.Item("<NameOfUserdefinedField>")

' For Example:
Set objField = objFields.Item("PersonRole")

End Sub

It's cdo.dll, and as the page I suggested explains, it's
part
of
your
Outlook installation. Rerun Outlook/Office setup if
necessary.

I Tried loading that dll and I get a message that says
"Error
Loading
DLL".
DO you know where I can get this dll and what its
name
is?
message
It's a CDO MAPI.Session object. Make sure you add the
CDO
1.21
library
to
your project. See http://www.slipstick.com/dev/cdo.htm
if
you're
new
to
CDO.


OK I Looked at the primer but I do not know how
to
dim
 
S

Sue Mosher [MVP]

Does your code actually instantiate objFields? In the sample you posted, the
statement instantiating objFields is remarked out.

John Galt said:
In the following statement when I use any of the 3 cdoVariables or the
Property Tag

i.e. Set ObjField = objFields.Item(&H10820040)
Set ObjField = objFields.Item(CdoPR_ACTION_DATE)



Sue Mosher said:
But which statement is giving you the runtime error?

Don't forget that you have to check for the existence of the field first,
before accessing its value, since CDO only stores fields in the Fields
collection if they have values.

John Galt said:
Here is the code so far.


Private Sub cmdTEST_CLick()
Dim objSession As MAPI.Session
Dim objFolder As MAPI.Folder
Dim objmessages As MAPI.Messages
Dim objFields As MAPI.Fields
Dim objmessage As MAPI.Message


Set objSession = CreateObject("MAPI.Session")
If Not objSession Is Nothing Then
strProfileName = "MS Exchange Settings"
objSession.Logon strProfileName, , False
End If

Set objFolder = objSession.GetDefaultFolder(CdoDefaultFolderContacts)
Set objFolder =
objSession.GetFolder("00000000515BA5871FC8D5119923000475762650C2960000")
'GetFolder("My Local E-Mail\Morang Cove Trading Company\MCTC Contacts")
' Get the first message of the contacts folder
' Note that it is still a message object
' So the class property will always return a value of CdoMsg
Set objmessages = objFolder.Messages
Set objmessage = objmessages.GetFirst()

' Get the fields collection of the contact item
'Set objFields = objmessage.Fields

' Get a single field using the MAPI property tag
Set ObjField = objFields.Item(1)

' For Example:
Set ObjField = objFields.Item(&H3001001E)
x = 0
On Error Resume Next

For I = 1 To objmessages.Count
Set objmessage = objmessages.GetNext()
Set objFields = objmessage.Fields
For x = 1 To 1000
If InStr(objmessage.Field("Categories"), "Buyer") > 0 Then
Debug.Print "x = " & x & " " & objFields(x)
End If
Next x
Next I

'*** Code to review *************
' If it is a Microsoft Outlook item you can either use
Set ObjField = objFields.Item("<PropertyTag>", "<PropertySetID>")

' For Example:
Set ObjField = objFields.Item("0x8013", "0820060000000000C000000000000046")

' Or the following syntax if you want to read the value directly
Value = objFields.Item("{" & "<PropertySetID>" & "}" &
"<PropertyTag>").Value

' For Example:
Value = objFields.Item("{0820060000000000C000000000000046}0x8535").Value

' If it is a Microsoft Outlook item with a custom field use the following
syntax:
Set ObjField = objFields.Item("<NameOfUserdefinedField>")

' For Example:
Set ObjField = objFields.Item("PersonRole")

End Sub





Code snippet?

I actually have this working (Well almost).
The original problem was to expose 3 particular fields in the contacts
folder:
1. Reminder time
2. Flag Status
3. Followup Flag

I use the CDO representations for these 3 fields:

1. CdoPR_FLAG_DUE_BY
2. CdoPR_FLAG_STATUS
3. CdoPR_ACTION_DATE

I still cannot get these variables. I get Run-time error '-2147221233
(8004010f'):
[Collaboration Data Objects - [MAPI_E_NOT_FOUND(8004010F)]]

Any pointers ???

Thanks

They data stamp on my CDO.DLL is 3/17/2002 3:29PM.
Is this the latest dll?


Yes I did add CDO 1.21.
I am now getting a type mismatch on the same statement.
It does not like cdoDefaultfolderscontacts or a numeric
constant
of
5
or
"Contacts".
I do not understand why this is failing.


Did you add a reference to CDO 1.21 to your project? You
can't
use
CDO
constants in your code until you do.

Also, I don't see that you're instantiating objSession anywhere.
This
is
the
minimum if you want it to use the same session that Outlook is
already
running under:

Set objSession = CreateObject("MAPI.Session")
objSession.Logon "", "", False, False
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



I reran now and have CDO.DLL!
I now Have MAPI.Session working.

The next part of the code that the sample shows is
Set objFolder =
objSession.GetDefaultFolder(CdoDefaultFolderContacts)

When I hit this statement in the debugger I get "Object Variable
or
with
block not set.


Here is my code taken from the example:

Private Sub cmdTEST_CLick()
Dim objSession As MAPI.Session
Dim objFolder As CDO.Folder
'Set objSession = oOutlook.CdoNamespace ' Get the contacts
folder
of
the
mailbox
Set objFolder =
objSession.GetDefaultFolder(CdoDefaultFolderContacts)
' Get the first message of the contacts folder
' Note that it is still a message object
' So the class property will always return a value of CdoMsg
'Set objMessages = objFolder.Messages
'Set objMessage = objMessages.GetFirst()

' Get the fields collection of the contact item
Set objFields = objMessage.Fields

' Get a single field using the MAPI property tag
Set objField = objFields.Item(PR_DISPLAY_NAME)

' For Example:
Set objField = objFields.Item(&H3001001E)

' If it is a Microsoft Outlook item you can either use
Set objField = objFields.Item("<PropertyTag>",
"<PropertySetID>")

' For Example:
Set objField = objFields.Item("0x8535",
"0820060000000000C000000000000046")

' Or the following syntax if you want to read the value directly
Value = objFields.Item("{" & "<PropertySetID>" & "}" &
"<PropertyTag>").Value

' For Example:
Value =
objFields.Item("{0820060000000000C000000000000046}0x8535").Value

' If it is a Microsoft Outlook item with a custom field
use
the
following
syntax:
Set objField = objFields.Item("<NameOfUserdefinedField>")

' For Example:
Set objField = objFields.Item("PersonRole")

End Sub

It's cdo.dll, and as the page I suggested explains, it's
part
of
your
Outlook installation. Rerun Outlook/Office setup if
necessary.

I Tried loading that dll and I get a message that says
"Error
Loading
DLL".
DO you know where I can get this dll and what its name
is?

message
It's a CDO MAPI.Session object. Make sure you
add
the
CDO
1.21
library
to
your project. See http://www.slipstick.com/dev/cdo.htm
if
you're
new
to
CDO.


OK I Looked at the primer but I do not know
how
 
J

John Galt

Again, many of the cdoPR... variables do not work, nor do the other methods
for viewing the values i.e.
debug.print
objFields.Item("{0006200800000000C000000000000046}0x802c")
or debug.print objFields.Item(&H10900003)

Also the origianl Outlook object I used allowed me to get Categories. CDO
does NOT.

Here is the working sub routine statements without any COMMENTED OUT.
This works except for my statements above.

Private Sub cmdTEST_CLick()
Dim objSession As MAPI.Session
Dim objFolder As MAPI.Folder
Dim objmessages As MAPI.Messages
Dim objFields As MAPI.Fields
Dim objmessage As MAPI.Message


Set objSession = CreateObject("MAPI.Session")
If Not objSession Is Nothing Then
strProfileName = "MS Exchange Settings"
objSession.Logon strProfileName, , False
End If

Set objFolder = objSession.GetDefaultFolder(CdoDefaultFolderContacts)
Set objFolder =
objSession.GetFolder("00000000515BA5871FC8D5119923000475762650C2960000") '
Get the first message of the contacts folder
' Note that it is still a message object
' So the class property will always return a value of CdoMsg
Set objmessages = objFolder.Messages

Set objmessage = objmessages.GetFirst()

On Error Resume Next
a = 2

For I = 2 To objmessages.Count
Set objmessage = objmessages.GetNext()
Set objFields = objmessage.Fields

If a = 1 Then 'InStr(objmessage.Field("Categories"), "Buyer") > 0
Then
Debug.Print "*********** Record # " & I & " ***********"
Debug.Print objFields(9)
Debug.Print objFields(53)
Debug.Print objFields(52)
Debug.Print objFields(72)
Debug.Print objFields(73)
Debug.Print objFields(76)
Debug.Print "***********************************"
Else
For x = 1 To 20000
If I = 29 Then
Debug.Print "x = " & x & " " & objFields(x)
End If
Next x

End If
Next I
End Sub

Sue Mosher said:
Does your code actually instantiate objFields? In the sample you posted, the
statement instantiating objFields is remarked out.

John Galt said:
In the following statement when I use any of the 3 cdoVariables or the
Property Tag

i.e. Set ObjField = objFields.Item(&H10820040)
Set ObjField = objFields.Item(CdoPR_ACTION_DATE)



Sue Mosher said:
But which statement is giving you the runtime error?

Don't forget that you have to check for the existence of the field first,
before accessing its value, since CDO only stores fields in the Fields
collection if they have values.

Here is the code so far.


Private Sub cmdTEST_CLick()
Dim objSession As MAPI.Session
Dim objFolder As MAPI.Folder
Dim objmessages As MAPI.Messages
Dim objFields As MAPI.Fields
Dim objmessage As MAPI.Message


Set objSession = CreateObject("MAPI.Session")
If Not objSession Is Nothing Then
strProfileName = "MS Exchange Settings"
objSession.Logon strProfileName, , False
End If

Set objFolder = objSession.GetDefaultFolder(CdoDefaultFolderContacts)
Set objFolder =
objSession.GetFolder("00000000515BA5871FC8D5119923000475762650C2960000")
'GetFolder("My Local E-Mail\Morang Cove Trading Company\MCTC Contacts")
' Get the first message of the contacts folder
' Note that it is still a message object
' So the class property will always return a value of CdoMsg
Set objmessages = objFolder.Messages
Set objmessage = objmessages.GetFirst()

' Get the fields collection of the contact item
'Set objFields = objmessage.Fields

' Get a single field using the MAPI property tag
Set ObjField = objFields.Item(1)

' For Example:
Set ObjField = objFields.Item(&H3001001E)
x = 0
On Error Resume Next

For I = 1 To objmessages.Count
Set objmessage = objmessages.GetNext()
Set objFields = objmessage.Fields
For x = 1 To 1000
If InStr(objmessage.Field("Categories"), "Buyer") > 0 Then
Debug.Print "x = " & x & " " & objFields(x)
End If
Next x
Next I

'*** Code to review *************
' If it is a Microsoft Outlook item you can either use
Set ObjField = objFields.Item("<PropertyTag>", "<PropertySetID>")

' For Example:
Set ObjField = objFields.Item("0x8013",
"0820060000000000C000000000000046")

' Or the following syntax if you want to read the value directly
Value = objFields.Item("{" & "<PropertySetID>" & "}" &
"<PropertyTag>").Value

' For Example:
Value = objFields.Item("{0820060000000000C000000000000046}0x8535").Value

' If it is a Microsoft Outlook item with a custom field use the following
syntax:
Set ObjField = objFields.Item("<NameOfUserdefinedField>")

' For Example:
Set ObjField = objFields.Item("PersonRole")

End Sub





Code snippet?

I actually have this working (Well almost).
The original problem was to expose 3 particular fields in the contacts
folder:
1. Reminder time
2. Flag Status
3. Followup Flag

I use the CDO representations for these 3 fields:

1. CdoPR_FLAG_DUE_BY
2. CdoPR_FLAG_STATUS
3. CdoPR_ACTION_DATE

I still cannot get these variables. I get Run-time error '-2147221233
(8004010f'):
[Collaboration Data Objects - [MAPI_E_NOT_FOUND(8004010F)]]

Any pointers ???

Thanks

They data stamp on my CDO.DLL is 3/17/2002 3:29PM.
Is this the latest dll?


Yes I did add CDO 1.21.
I am now getting a type mismatch on the same statement.
It does not like cdoDefaultfolderscontacts or a numeric constant
of
5
or
"Contacts".
I do not understand why this is failing.


Did you add a reference to CDO 1.21 to your project? You can't
use
CDO
constants in your code until you do.

Also, I don't see that you're instantiating objSession anywhere.
This
is
the
minimum if you want it to use the same session that
Outlook
is
already
running under:

Set objSession = CreateObject("MAPI.Session")
objSession.Logon "", "", False, False
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



I reran now and have CDO.DLL!
I now Have MAPI.Session working.

The next part of the code that the sample shows is
Set objFolder =
objSession.GetDefaultFolder(CdoDefaultFolderContacts)

When I hit this statement in the debugger I get "Object
Variable
or
with
block not set.


Here is my code taken from the example:

Private Sub cmdTEST_CLick()
Dim objSession As MAPI.Session
Dim objFolder As CDO.Folder
'Set objSession = oOutlook.CdoNamespace ' Get the contacts
folder
of
the
mailbox
Set objFolder =
objSession.GetDefaultFolder(CdoDefaultFolderContacts)
' Get the first message of the contacts folder
' Note that it is still a message object
' So the class property will always return a value of CdoMsg
'Set objMessages = objFolder.Messages
'Set objMessage = objMessages.GetFirst()

' Get the fields collection of the contact item
Set objFields = objMessage.Fields

' Get a single field using the MAPI property tag
Set objField = objFields.Item(PR_DISPLAY_NAME)

' For Example:
Set objField = objFields.Item(&H3001001E)

' If it is a Microsoft Outlook item you can either use
Set objField = objFields.Item("<PropertyTag>",
"<PropertySetID>")

' For Example:
Set objField = objFields.Item("0x8535",
"0820060000000000C000000000000046")

' Or the following syntax if you want to read the value
directly
Value = objFields.Item("{" & "<PropertySetID>" & "}" &
"<PropertyTag>").Value

' For Example:
Value =
objFields.Item("{0820060000000000C000000000000046}0x8535").Value

' If it is a Microsoft Outlook item with a custom field use
the
following
syntax:
Set objField =
objFields.Item( said:
' For Example:
Set objField = objFields.Item("PersonRole")

End Sub

message
It's cdo.dll, and as the page I suggested
explains,
it's
part
of
your
Outlook installation. Rerun Outlook/Office setup if
necessary.

I Tried loading that dll and I get a message
that
says
"Error
Loading
DLL".
DO you know where I can get this dll and what
its
name
 
S

Sue Mosher [MVP]

As I said, when using CDO, you should not assume that a MAPI property is
present on the item. If it does not contain data, it will not be present.
One approach is to set an object variable to the field in question, test If
Not objField Is Nothing and only then attempt to get the value of the field.
The other way to deal with this is to access the value directly, but handle
the error that results if the property is not present. The page at
http://www.cdolive.com/cdo10.htm explains this. If you want to set the
value, then you add the field, then set its value. Does that make sense? I
know it's different from Outlook objects, but there is a certain logic to
it. CDO *always* requires good error handling; the errors are expected and
do not necessarily mean there's something wrong with your code.

So in your case, if you get an error when trying to get
objFields.Item((&H10900003).Value, that just means there is no flag on the
contact.

The CDO Message object directly supports a Categories field -- i.e.
Message.Categories (check the object browser!) -- but it's a Variant Array,
not a string.

Also note that you should *never* assume that an item in a contacts folder
is a contact, because it could be a distribution list.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



John Galt said:
Again, many of the cdoPR... variables do not work, nor do the other methods
for viewing the values i.e.
debug.print
objFields.Item("{0006200800000000C000000000000046}0x802c")
or debug.print objFields.Item(&H10900003)

Also the origianl Outlook object I used allowed me to get Categories. CDO
does NOT.

Here is the working sub routine statements without any COMMENTED OUT.
This works except for my statements above.

Private Sub cmdTEST_CLick()
Dim objSession As MAPI.Session
Dim objFolder As MAPI.Folder
Dim objmessages As MAPI.Messages
Dim objFields As MAPI.Fields
Dim objmessage As MAPI.Message


Set objSession = CreateObject("MAPI.Session")
If Not objSession Is Nothing Then
strProfileName = "MS Exchange Settings"
objSession.Logon strProfileName, , False
End If

Set objFolder = objSession.GetDefaultFolder(CdoDefaultFolderContacts)
Set objFolder =
objSession.GetFolder("00000000515BA5871FC8D5119923000475762650C2960000") '
Get the first message of the contacts folder
' Note that it is still a message object
' So the class property will always return a value of CdoMsg
Set objmessages = objFolder.Messages

Set objmessage = objmessages.GetFirst()

On Error Resume Next
a = 2

For I = 2 To objmessages.Count
Set objmessage = objmessages.GetNext()
Set objFields = objmessage.Fields

If a = 1 Then 'InStr(objmessage.Field("Categories"), "Buyer") > 0
Then
Debug.Print "*********** Record # " & I & " ***********"
Debug.Print objFields(9)
Debug.Print objFields(53)
Debug.Print objFields(52)
Debug.Print objFields(72)
Debug.Print objFields(73)
Debug.Print objFields(76)
Debug.Print "***********************************"
Else
For x = 1 To 20000
If I = 29 Then
Debug.Print "x = " & x & " " & objFields(x)
End If
Next x

End If
Next I
End Sub

Sue Mosher said:
Does your code actually instantiate objFields? In the sample you posted, the
statement instantiating objFields is remarked out.

John Galt said:
In the following statement when I use any of the 3 cdoVariables or the
Property Tag

i.e. Set ObjField = objFields.Item(&H10820040)
Set ObjField = objFields.Item(CdoPR_ACTION_DATE)



But which statement is giving you the runtime error?

Don't forget that you have to check for the existence of the field first,
before accessing its value, since CDO only stores fields in the Fields
collection if they have values.

Here is the code so far.


Private Sub cmdTEST_CLick()
Dim objSession As MAPI.Session
Dim objFolder As MAPI.Folder
Dim objmessages As MAPI.Messages
Dim objFields As MAPI.Fields
Dim objmessage As MAPI.Message


Set objSession = CreateObject("MAPI.Session")
If Not objSession Is Nothing Then
strProfileName = "MS Exchange Settings"
objSession.Logon strProfileName, , False
End If

Set objFolder = objSession.GetDefaultFolder(CdoDefaultFolderContacts)
Set objFolder =
objSession.GetFolder("00000000515BA5871FC8D5119923000475762650C2960000")
'GetFolder("My Local E-Mail\Morang Cove Trading Company\MCTC Contacts")
' Get the first message of the contacts folder
' Note that it is still a message object
' So the class property will always return a value of CdoMsg
Set objmessages = objFolder.Messages
Set objmessage = objmessages.GetFirst()

' Get the fields collection of the contact item
'Set objFields = objmessage.Fields

' Get a single field using the MAPI property tag
Set ObjField = objFields.Item(1)

' For Example:
Set ObjField = objFields.Item(&H3001001E)
x = 0
On Error Resume Next

For I = 1 To objmessages.Count
Set objmessage = objmessages.GetNext()
Set objFields = objmessage.Fields
For x = 1 To 1000
If InStr(objmessage.Field("Categories"), "Buyer") > 0 Then
Debug.Print "x = " & x & " " & objFields(x)
End If
Next x
Next I

'*** Code to review *************
' If it is a Microsoft Outlook item you can either use
Set ObjField = objFields.Item("<PropertyTag>", "<PropertySetID>")

' For Example:
Set ObjField = objFields.Item("0x8013",
"0820060000000000C000000000000046")

' Or the following syntax if you want to read the value directly
Value = objFields.Item("{" & "<PropertySetID>" & "}" &
"<PropertyTag>").Value

' For Example:
Value = objFields.Item("{0820060000000000C000000000000046}0x8535").Value

' If it is a Microsoft Outlook item with a custom field use the
following
syntax:
Set ObjField = objFields.Item("<NameOfUserdefinedField>")

' For Example:
Set ObjField = objFields.Item("PersonRole")

End Sub





Code snippet?

I actually have this working (Well almost).
The original problem was to expose 3 particular fields in the
contacts
folder:
1. Reminder time
2. Flag Status
3. Followup Flag

I use the CDO representations for these 3 fields:

1. CdoPR_FLAG_DUE_BY
2. CdoPR_FLAG_STATUS
3. CdoPR_ACTION_DATE

I still cannot get these variables. I get Run-time error
'-2147221233
(8004010f'):
[Collaboration Data Objects - [MAPI_E_NOT_FOUND(8004010F)]]

Any pointers ???

Thanks

They data stamp on my CDO.DLL is 3/17/2002 3:29PM.
Is this the latest dll?


Yes I did add CDO 1.21.
I am now getting a type mismatch on the same statement.
It does not like cdoDefaultfolderscontacts or a numeric constant
of
5
or
"Contacts".
I do not understand why this is failing.


Did you add a reference to CDO 1.21 to your project? You can't
use
CDO
constants in your code until you do.

Also, I don't see that you're instantiating objSession
anywhere.
This
is
the
minimum if you want it to use the same session that
Outlook
is
already
running under:

Set objSession = CreateObject("MAPI.Session")
objSession.Logon "", "", False, False
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



I reran now and have CDO.DLL!
I now Have MAPI.Session working.

The next part of the code that the sample shows is
Set objFolder =
objSession.GetDefaultFolder(CdoDefaultFolderContacts)

When I hit this statement in the debugger I get "Object
Variable
or
with
block not set.


Here is my code taken from the example:

Private Sub cmdTEST_CLick()
Dim objSession As MAPI.Session
Dim objFolder As CDO.Folder
'Set objSession = oOutlook.CdoNamespace ' Get the contacts
folder
of
the
mailbox
Set objFolder =
objSession.GetDefaultFolder(CdoDefaultFolderContacts)
' Get the first message of the contacts folder
' Note that it is still a message object
' So the class property will always return a value of CdoMsg
'Set objMessages = objFolder.Messages
'Set objMessage = objMessages.GetFirst()

' Get the fields collection of the contact item
Set objFields = objMessage.Fields

' Get a single field using the MAPI property tag
Set objField = objFields.Item(PR_DISPLAY_NAME)

' For Example:
Set objField = objFields.Item(&H3001001E)

' If it is a Microsoft Outlook item you can either use
Set objField = objFields.Item("<PropertyTag>",
"<PropertySetID>")

' For Example:
Set objField = objFields.Item("0x8535",
"0820060000000000C000000000000046")

' Or the following syntax if you want to read the value
directly
Value = objFields.Item("{" & "<PropertySetID>" & "}" &
"<PropertyTag>").Value

' For Example:
Value =
objFields.Item("{0820060000000000C000000000000046}0x8535").Value

' If it is a Microsoft Outlook item with a custom
field
use
the
following
syntax:
Set objField =
objFields.Item( said:
' For Example:
Set objField = objFields.Item("PersonRole")

End Sub

message
It's cdo.dll, and as the page I suggested explains,
it's
part
of
your
Outlook installation. Rerun Outlook/Office setup if
necessary.

I Tried loading that dll and I get a message that
says
"Error
Loading
DLL".
DO you know where I can get this dll and what its
name
is?

you
add know
how
 
J

John Galt

Hi Sue

OK. I understand that CDO does not create a an object that does not have
a value.
I am looking for values in fields that I know ABOSOLUTELY have a value.
Fields that do not get handled by "On error resume next".

In this particular case I am using a contacts folder that is purely
contacts.
I created it and no records get in it that have not filled in the necessary
fields.


The CDO Message object does "appear" to handle .categories. I used the
object browser to find it.
Every time I try to use it I get an error i.e. debug print
objmessage.Categories RUN TIME ERROR 13 Type mismatch.
How do I use the Variant array????


Are you getting tired of me yet?

Sue Mosher said:
As I said, when using CDO, you should not assume that a MAPI property is
present on the item. If it does not contain data, it will not be present.
One approach is to set an object variable to the field in question, test If
Not objField Is Nothing and only then attempt to get the value of the field.
The other way to deal with this is to access the value directly, but handle
the error that results if the property is not present. The page at
http://www.cdolive.com/cdo10.htm explains this. If you want to set the
value, then you add the field, then set its value. Does that make sense? I
know it's different from Outlook objects, but there is a certain logic to
it. CDO *always* requires good error handling; the errors are expected and
do not necessarily mean there's something wrong with your code.

So in your case, if you get an error when trying to get
objFields.Item((&H10900003).Value, that just means there is no flag on the
contact.

The CDO Message object directly supports a Categories field -- i.e.
Message.Categories (check the object browser!) -- but it's a Variant Array,
not a string.

Also note that you should *never* assume that an item in a contacts folder
is a contact, because it could be a distribution list.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



John Galt said:
Again, many of the cdoPR... variables do not work, nor do the other methods
for viewing the values i.e.
debug.print
objFields.Item("{0006200800000000C000000000000046}0x802c")
or debug.print objFields.Item(&H10900003)

Also the origianl Outlook object I used allowed me to get Categories. CDO
does NOT.

Here is the working sub routine statements without any COMMENTED OUT.
This works except for my statements above.

Private Sub cmdTEST_CLick()
Dim objSession As MAPI.Session
Dim objFolder As MAPI.Folder
Dim objmessages As MAPI.Messages
Dim objFields As MAPI.Fields
Dim objmessage As MAPI.Message


Set objSession = CreateObject("MAPI.Session")
If Not objSession Is Nothing Then
strProfileName = "MS Exchange Settings"
objSession.Logon strProfileName, , False
End If

Set objFolder = objSession.GetDefaultFolder(CdoDefaultFolderContacts)
Set objFolder =
objSession.GetFolder("00000000515BA5871FC8D5119923000475762650C2960000") '
Get the first message of the contacts folder
' Note that it is still a message object
' So the class property will always return a value of CdoMsg
Set objmessages = objFolder.Messages

Set objmessage = objmessages.GetFirst()

On Error Resume Next
a = 2

For I = 2 To objmessages.Count
Set objmessage = objmessages.GetNext()
Set objFields = objmessage.Fields

If a = 1 Then 'InStr(objmessage.Field("Categories"), "Buyer") > 0
Then
Debug.Print "*********** Record # " & I & " ***********"
Debug.Print objFields(9)
Debug.Print objFields(53)
Debug.Print objFields(52)
Debug.Print objFields(72)
Debug.Print objFields(73)
Debug.Print objFields(76)
Debug.Print "***********************************"
Else
For x = 1 To 20000
If I = 29 Then
Debug.Print "x = " & x & " " & objFields(x)
End If
Next x

End If
Next I
End Sub

Sue Mosher said:
Does your code actually instantiate objFields? In the sample you
posted,
the
statement instantiating objFields is remarked out.

In the following statement when I use any of the 3 cdoVariables or the
Property Tag

i.e. Set ObjField = objFields.Item(&H10820040)
Set ObjField = objFields.Item(CdoPR_ACTION_DATE)



But which statement is giving you the runtime error?

Don't forget that you have to check for the existence of the field
first,
before accessing its value, since CDO only stores fields in the Fields
collection if they have values.

Here is the code so far.


Private Sub cmdTEST_CLick()
Dim objSession As MAPI.Session
Dim objFolder As MAPI.Folder
Dim objmessages As MAPI.Messages
Dim objFields As MAPI.Fields
Dim objmessage As MAPI.Message


Set objSession = CreateObject("MAPI.Session")
If Not objSession Is Nothing Then
strProfileName = "MS Exchange Settings"
objSession.Logon strProfileName, , False
End If

Set objFolder = objSession.GetDefaultFolder(CdoDefaultFolderContacts)
Set objFolder =

objSession.GetFolder("00000000515BA5871FC8D5119923000475762650C2960000")
'GetFolder("My Local E-Mail\Morang Cove Trading Company\MCTC
Contacts")
' Get the first message of the contacts folder
' Note that it is still a message object
' So the class property will always return a value of CdoMsg
Set objmessages = objFolder.Messages
Set objmessage = objmessages.GetFirst()

' Get the fields collection of the contact item
'Set objFields = objmessage.Fields

' Get a single field using the MAPI property tag
Set ObjField = objFields.Item(1)

' For Example:
Set ObjField = objFields.Item(&H3001001E)
x = 0
On Error Resume Next

For I = 1 To objmessages.Count
Set objmessage = objmessages.GetNext()
Set objFields = objmessage.Fields
For x = 1 To 1000
If InStr(objmessage.Field("Categories"), "Buyer") > 0 Then
Debug.Print "x = " & x & " " & objFields(x)
End If
Next x
Next I

'*** Code to review *************
' If it is a Microsoft Outlook item you can either use
Set ObjField = objFields.Item("<PropertyTag>",
' For Example:
Set ObjField = objFields.Item("0x8013",
"0820060000000000C000000000000046")

' Or the following syntax if you want to read the value directly
Value = objFields.Item("{" & "<PropertySetID>" & "}" &
"<PropertyTag>").Value

' For Example:
Value =
objFields.Item("{0820060000000000C000000000000046}0x8535").Value

' If it is a Microsoft Outlook item with a custom field use the
following
syntax:
Set ObjField = objFields.Item("<NameOfUserdefinedField>")

' For Example:
Set ObjField = objFields.Item("PersonRole")

End Sub





Code snippet?

I actually have this working (Well almost).
The original problem was to expose 3 particular fields in the
contacts
folder:
1. Reminder time
2. Flag Status
3. Followup Flag

I use the CDO representations for these 3 fields:

1. CdoPR_FLAG_DUE_BY
2. CdoPR_FLAG_STATUS
3. CdoPR_ACTION_DATE

I still cannot get these variables. I get Run-time error
'-2147221233
(8004010f'):
[Collaboration Data Objects - [MAPI_E_NOT_FOUND(8004010F)]]

Any pointers ???

Thanks

They data stamp on my CDO.DLL is 3/17/2002 3:29PM.
Is this the latest dll?


Yes I did add CDO 1.21.
I am now getting a type mismatch on the same statement.
It does not like cdoDefaultfolderscontacts or a numeric
constant
of
5
or
"Contacts".
I do not understand why this is failing.


Did you add a reference to CDO 1.21 to your project? You
can't
use
CDO
constants in your code until you do.

Also, I don't see that you're instantiating objSession
anywhere.
This
is
the
minimum if you want it to use the same session that Outlook
is
already
running under:

Set objSession = CreateObject("MAPI.Session")
objSession.Logon "", "", False, False
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



I reran now and have CDO.DLL!
I now Have MAPI.Session working.

The next part of the code that the sample shows is
Set objFolder =
objSession.GetDefaultFolder(CdoDefaultFolderContacts)

When I hit this statement in the debugger I get "Object
Variable
or
with
block not set.


Here is my code taken from the example:

Private Sub cmdTEST_CLick()
Dim objSession As MAPI.Session
Dim objFolder As CDO.Folder
'Set objSession = oOutlook.CdoNamespace ' Get the
contacts
folder
of
the
mailbox
Set objFolder =
objSession.GetDefaultFolder(CdoDefaultFolderContacts)
' Get the first message of the contacts folder
' Note that it is still a message object
' So the class property will always return a value of
CdoMsg
'Set objMessages = objFolder.Messages
'Set objMessage = objMessages.GetFirst()

' Get the fields collection of the contact item
Set objFields = objMessage.Fields

' Get a single field using the MAPI property tag
Set objField = objFields.Item(PR_DISPLAY_NAME)

' For Example:
Set objField = objFields.Item(&H3001001E)

' If it is a Microsoft Outlook item you can either use
Set objField = objFields.Item("<PropertyTag>",
"<PropertySetID>")

' For Example:
Set objField = objFields.Item("0x8535",
"0820060000000000C000000000000046")

' Or the following syntax if you want to read the value
directly
Value = objFields.Item("{" & "<PropertySetID>" & "}" &
"<PropertyTag>").Value

' For Example:
Value =
objFields.Item("{0820060000000000C000000000000046}0x8535").Value

' If it is a Microsoft Outlook item with a custom field
use
the
following
syntax:
Set objField =
 
J

John Galt

Well I set a variable = to the object.message.categories and was able to
manipulate the array.
Thank you for all your help on this.
It was a great exercise. I am now going to attempt to create a fax from the
contacts with the correct category.

Should be fun!


John Galt said:
Hi Sue

OK. I understand that CDO does not create a an object that does not have
a value.
I am looking for values in fields that I know ABOSOLUTELY have a value.
Fields that do not get handled by "On error resume next".

In this particular case I am using a contacts folder that is purely
contacts.
I created it and no records get in it that have not filled in the necessary
fields.


The CDO Message object does "appear" to handle .categories. I used the
object browser to find it.
Every time I try to use it I get an error i.e. debug print
objmessage.Categories RUN TIME ERROR 13 Type mismatch.
How do I use the Variant array????


Are you getting tired of me yet?

Sue Mosher said:
As I said, when using CDO, you should not assume that a MAPI property is
present on the item. If it does not contain data, it will not be present.
One approach is to set an object variable to the field in question, test If
Not objField Is Nothing and only then attempt to get the value of the field.
The other way to deal with this is to access the value directly, but handle
the error that results if the property is not present. The page at
http://www.cdolive.com/cdo10.htm explains this. If you want to set the
value, then you add the field, then set its value. Does that make sense? I
know it's different from Outlook objects, but there is a certain logic to
it. CDO *always* requires good error handling; the errors are expected and
do not necessarily mean there's something wrong with your code.

So in your case, if you get an error when trying to get
objFields.Item((&H10900003).Value, that just means there is no flag on the
contact.

The CDO Message object directly supports a Categories field -- i.e.
Message.Categories (check the object browser!) -- but it's a Variant Array,
not a string.

Also note that you should *never* assume that an item in a contacts folder
is a contact, because it could be a distribution list.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
objSession.GetFolder("00000000515BA5871FC8D5119923000475762650C2960000")
'
Get the first message of the contacts folder
' Note that it is still a message object
' So the class property will always return a value of CdoMsg
Set objmessages = objFolder.Messages

Set objmessage = objmessages.GetFirst()

On Error Resume Next
a = 2

For I = 2 To objmessages.Count
Set objmessage = objmessages.GetNext()
Set objFields = objmessage.Fields

If a = 1 Then 'InStr(objmessage.Field("Categories"), "Buyer")
0
Then
Debug.Print "*********** Record # " & I & " ***********"
Debug.Print objFields(9)
Debug.Print objFields(53)
Debug.Print objFields(52)
Debug.Print objFields(72)
Debug.Print objFields(73)
Debug.Print objFields(76)
Debug.Print "***********************************"
Else
For x = 1 To 20000
If I = 29 Then
Debug.Print "x = " & x & " " & objFields(x)
End If
Next x

End If
Next I
End Sub

Does your code actually instantiate objFields? In the sample you posted,
the
statement instantiating objFields is remarked out.

In the following statement when I use any of the 3 cdoVariables or the
Property Tag

i.e. Set ObjField = objFields.Item(&H10820040)
Set ObjField = objFields.Item(CdoPR_ACTION_DATE)



But which statement is giving you the runtime error?

Don't forget that you have to check for the existence of the field
first,
before accessing its value, since CDO only stores fields in the Fields
collection if they have values.

Here is the code so far.


Private Sub cmdTEST_CLick()
Dim objSession As MAPI.Session
Dim objFolder As MAPI.Folder
Dim objmessages As MAPI.Messages
Dim objFields As MAPI.Fields
Dim objmessage As MAPI.Message


Set objSession = CreateObject("MAPI.Session")
If Not objSession Is Nothing Then
strProfileName = "MS Exchange Settings"
objSession.Logon strProfileName, , False
End If

Set objFolder =
objSession.GetDefaultFolder(CdoDefaultFolderContacts)
Set objFolder =

objSession.GetFolder("00000000515BA5871FC8D5119923000475762650C2960000")
'GetFolder("My Local E-Mail\Morang Cove Trading Company\MCTC
Contacts")
' Get the first message of the contacts folder
' Note that it is still a message object
' So the class property will always return a value of CdoMsg
Set objmessages = objFolder.Messages
Set objmessage = objmessages.GetFirst()

' Get the fields collection of the contact item
'Set objFields = objmessage.Fields

' Get a single field using the MAPI property tag
Set ObjField = objFields.Item(1)

' For Example:
Set ObjField = objFields.Item(&H3001001E)
x = 0
On Error Resume Next

For I = 1 To objmessages.Count
Set objmessage = objmessages.GetNext()
Set objFields = objmessage.Fields
For x = 1 To 1000
If InStr(objmessage.Field("Categories"), "Buyer") > 0 Then
Debug.Print "x = " & x & " " & objFields(x)
End If
Next x
Next I

'*** Code to review *************
' If it is a Microsoft Outlook item you can either use
Set ObjField = objFields.Item("<PropertyTag>",
' For Example:
Set ObjField = objFields.Item("0x8013",
"0820060000000000C000000000000046")

' Or the following syntax if you want to read the value directly
Value = objFields.Item("{" & "<PropertySetID>" & "}" &
"<PropertyTag>").Value

' For Example:
Value =
objFields.Item("{0820060000000000C000000000000046}0x8535").Value

' If it is a Microsoft Outlook item with a custom field use the
following
syntax:
Set ObjField = objFields.Item("<NameOfUserdefinedField>")

' For Example:
Set ObjField = objFields.Item("PersonRole")

End Sub





Code snippet?

I actually have this working (Well almost).
The original problem was to expose 3 particular fields in the
contacts
folder:
1. Reminder time
2. Flag Status
3. Followup Flag

I use the CDO representations for these 3 fields:

1. CdoPR_FLAG_DUE_BY
2. CdoPR_FLAG_STATUS
3. CdoPR_ACTION_DATE

I still cannot get these variables. I get Run-time error
'-2147221233
(8004010f'):
[Collaboration Data Objects - [MAPI_E_NOT_FOUND(8004010F)]]

Any pointers ???

Thanks

They data stamp on my CDO.DLL is 3/17/2002 3:29PM.
Is this the latest dll?


Yes I did add CDO 1.21.
I am now getting a type mismatch on the same statement.
It does not like cdoDefaultfolderscontacts or a numeric
constant
of
5
or
"Contacts".
I do not understand why this is failing.


Did you add a reference to CDO 1.21 to your project? You
can't
use
CDO
constants in your code until you do.

Also, I don't see that you're instantiating objSession
anywhere.
This
is
the
minimum if you want it to use the same session that
Outlook
is
already
running under:

Set objSession = CreateObject("MAPI.Session")
objSession.Logon "", "", False, False
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



I reran now and have CDO.DLL!
I now Have MAPI.Session working.

The next part of the code that the sample shows is
Set objFolder =
objSession.GetDefaultFolder(CdoDefaultFolderContacts)

When I hit this statement in the debugger I get "Object
Variable
or
with
block not set.


Here is my code taken from the example:

Private Sub cmdTEST_CLick()
Dim objSession As MAPI.Session
Dim objFolder As CDO.Folder
'Set objSession = oOutlook.CdoNamespace ' Get the
contacts
folder
of
the
mailbox
Set objFolder =
objSession.GetDefaultFolder(CdoDefaultFolderContacts)
' Get the first message of the contacts folder
' Note that it is still a message object
' So the class property will always return a value of
CdoMsg
'Set objMessages = objFolder.Messages
'Set objMessage = objMessages.GetFirst()

' Get the fields collection of the contact item
Set objFields = objMessage.Fields

' Get a single field using the MAPI property tag
Set objField = objFields.Item(PR_DISPLAY_NAME)

' For Example:
Set objField = objFields.Item(&H3001001E)

' If it is a Microsoft Outlook item you can either use
Set objField = objFields.Item("<PropertyTag>",
"<PropertySetID>")

' For Example:
Set objField = objFields.Item("0x8535",
"0820060000000000C000000000000046")

' Or the following syntax if you want to read the value
directly
Value = objFields.Item("{" & "<PropertySetID>" &
"}"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top