Outlook Contacts in Excell or Access

J

John Galt

Can any one give me samples or suggest where I may find samples of reading
Outlook Contacts from Access or Excel.
I want to create a merge program that sends fax's to requestors (who exist
in
the contact folder).

Examples I have found do not seem to work so I am hoping someone here has
experience with this.

In addition to the original request:

I can link to my contacts folder just fine. I see many of the fields I need
for a report but there are some that I cannot find.

I am looking to pull the report for Items flagged for follow-up or phone
calls on a certain date. Also, I need to view them by Category.

I cannot find category or the reminder flag and contents of the reminder.



Any help or a custom control that might work would be great.



Thanks in Advance
 
S

Sue Mosher [MVP]

These pages may be useful:

http://www.slipstick.com/dev/customimport.htm
http://www.slipstick.com/dev/vb.htm

The linked table method has major limitations, including the inability to
show even all the reasonably important fields. While articles have been
written on how to expand on this method's obvious features, I've never been
able to duplicate the results. See
http://www.slipstick.com/dev/database.htm#linkedtables .

That page will also give you other ideas on how to work with databases and
Outlook together.
 
J

John Galt

Sue,

This is the code I have so far.

Private Sub cmdTEST_Click()
Dim oDatabase
Dim rs1 As ADODB.Recordset
Dim dbe
Dim wks
Dim dbs
Dim nms
Dim fld
Dim itms
Dim itm

Const olFolderContacts = 10
'###########################################
'# Set Objects
'###########################################

Set adoconn = CreateObject("ADODB.Connection")

accessConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Exchange 4.0;MAPILEVEL=;Database=C:\Temp;"


adoconn.ConnectionString = accessConnect
adoconn.Open accessConnect



' get record set

Set rs1 = adoconn.Execute("select * from Contacts")


I get an error on the execute statement that says "The MS Jet Database
engine could not find the object. Make sure you spell...."

Any help you can give me here?
 
S

Sue Mosher [MVP]

This is pretty much a dead-end, I think. As Ken Slovak posted here recently
in another thread, you just can't get to all the fields you need through
database techniques. The solution is to access items directly through the
Outlook object model.

FWIW, I can't get the code to work on Outlook 2003 myself.

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

John Galt

Well I did get this working to a point.
I cannot seem to figure out how to change to any folder I want to thru the
Outlook.Application.

Here is what I have so far.

Private Sub cmdTEST_Click()

Dim oOutlook As New Outlook.Application
Dim colItems As Items
Dim tblContacts As Recordset
Dim upContactId As UserProperty
Dim strMessage As String
Dim objFolder As Outlook.MAPIFolder


'Get a reference to the Items collection of the contacts folder.


Set colItems = oOutlook.GetNamespace("MAPI"). _
GetDefaultFolder(olFolderContacts).Items

This gives me the "Default" contacts folder to walk thru.
I need to change to another folder and am having trouble doing so.
Any Clues???
 
J

John Galt

I did that and am able to get the correct folder!!!!!
Now is there anyway to expose the available field names i.e. FullName,
BusineAddress etc... So I can see what is available?

Thanks for your help
 
S

Sue Mosher [MVP]

When in doubt, check the object browser: Press ALt+F11 to open the VBA
environment in Outlook, then press F2.
 
J

John Galt

I tried that but I Can't find anywhere that shows me the Column Names that I
can use.
For instance I guessed at .Fullname and .BusinessAddress but I cannot find a
column name for "ItemFlag" or "FollowUpFlag.

Any other ideas?

Thanks again
 
J

John Galt

OOOPS. Spoke to soon.
I found the columns but the ones I need do not exist.
Now I'm angry. All this work and the columns I need are not accessible.
aaaarrrrrrrrrrrrrrrrrrrrrrrrrrggggggggggggggggggggghhhhhhhhhhhhhhhhhhhhhhhhh
h!
 
S

Sue Mosher [MVP]

Do you want us to try to read your mind to understand what you're looking
for?
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
J

John Galt

I am looking for 3 specific columns that don't seem to be accessible. They
are:
1. Reminder time
2. Flag Status
3. Followup Flag

These are part of contact views and I want to be able to see them from
within access Just like the other columns such as FullName,
BusinessAddressStreet.

If they are part of Outlook why can I not see them as part of the
Outlook.Application?
 
J

John Galt

OK I Looked at the primer but I do not know how to dim the variable
objSession.
i.e.
Set objFolder = objSession.GetDefaultFolder(CdoDefaultFolderContacts)


Please advise.
 
S

Sue Mosher [MVP]

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.
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
J

John Galt

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?
 
S

Sue Mosher [MVP]

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

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

John Galt

According to Microsoft it is called CDONTS.DLL.
CDO.DLL is the old old old version.
I have the cdonts.dll and when I try to add the dll it says that it is NTS
ver. 1.2 NOT 1.2.1.

I have all of the latest updates from MS installed for both XP and Office
Professional.
Any other hints that might help me?
 
S

Sue Mosher [MVP]

No, no, no. Cdonts.dll is a completely different library, not related to
Outlook at all. What you want is Collaboration Data Objects, CDO 1.21, which
is an optional Outlook component. Did you rerun Office setup as I suggested?
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
J

John Galt

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
 

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