nkjohnson
asked on
Visual Basic Mapi/CDO contacts
Hi,
I am trying to pull data from my Oulook contacts folder using CDO. I am very new to CDO, and have messed around with a couple of things, but keep getting errors. The most popular one seems to be Error in Loading DLL. Below is a snippet from my code. Right now all I am trying to do is display a field by using the field name.
Anyone have any ideas
Sub main()
Set objSession = CreateObject("MAPI.Session ")
With objSession
.Logon
Set objAddressList = AddressBookExists("Contact s")
Set objAddressEntries = objAddressList.AddressEntr ies
For Each objAddressEntry In objAddressEntries
Msgbox objAddressEntry.Fields.Ite m(CDOPR_IN ITIALS)
Next
End With
End Sub
Public Function AddressBookExists(sAddress BookName As String) As AddressList
Dim objAddressList As AddressList
For Each objAddressList In objSession.AddressLists
If objAddressList.Name = sAddressBookName Then
Set AddressBookExists = objAddressList
Exit Function
End If
Next objAddressList
Set objAddressList = Nothing
End Function
I am trying to pull data from my Oulook contacts folder using CDO. I am very new to CDO, and have messed around with a couple of things, but keep getting errors. The most popular one seems to be Error in Loading DLL. Below is a snippet from my code. Right now all I am trying to do is display a field by using the field name.
Anyone have any ideas
Sub main()
Set objSession = CreateObject("MAPI.Session
With objSession
.Logon
Set objAddressList = AddressBookExists("Contact
Set objAddressEntries = objAddressList.AddressEntr
For Each objAddressEntry In objAddressEntries
Msgbox objAddressEntry.Fields.Ite
Next
End With
End Sub
Public Function AddressBookExists(sAddress
Dim objAddressList As AddressList
For Each objAddressList In objSession.AddressLists
If objAddressList.Name = sAddressBookName Then
Set AddressBookExists = objAddressList
Exit Function
End If
Next objAddressList
Set objAddressList = Nothing
End Function
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
More simply
Const CdoDefaultFolderContacts = 5
Sub Main2()
Dim objSession, oFolder, oMessage
Set objSession = CreateObject("MAPI.Session ")
With objSession
.Logon , , False, False
Set oFolder = .GetDefaultFolder(CdoDefau ltFolderCo ntacts)
For Each oMessage In oFolder.Messages
MsgBox oMessage.Fields.Item(CDOPR _INITIALS)
Next
End With
End Sub
Const CdoDefaultFolderContacts = 5
Sub Main2()
Dim objSession, oFolder, oMessage
Set objSession = CreateObject("MAPI.Session
With objSession
.Logon , , False, False
Set oFolder = .GetDefaultFolder(CdoDefau
For Each oMessage In oFolder.Messages
MsgBox oMessage.Fields.Item(CDOPR
Next
End With
End Sub
ASKER
brettdj I am still getting the Error in loading DLL error on this line,
MsgBox oMessage.Fields.Item(CDOPR _INITIALS) : Error # 48, Error in Loading DLL
It is pulling a Message because when I run a cursor over the message it gives me the first name in my contact folder.
MsgBox oMessage.Fields.Item(CDOPR
It is pulling a Message because when I run a cursor over the message it gives me the first name in my contact folder.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I apologize for the delay.
Thanks for the reminder.
Thanks for the reminder.
Note that you can Logon automatically with
.Logon , , False, False
Cheers
Dave
Sub Main()
Dim objSession, oFolder, oMessage
Set objSession = CreateObject("MAPI.Session
With objSession
.Logon , , False, False
Set oFolder = .InfoStores("Mailbox - Brett, David D").RootFolder
Set oFolder = oFolder.Folders("Contacts"
For Each oMessage In oFolder.Messages
MsgBox oMessage.Fields.Item(CDOPR
Next
End With
End Sub