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