I'm trying to use some VBA in Outlook 2010 to bring in pictures for a contact list. When I last tried this in Outlook 2007, it worked fine. But now, I've been upgraded to Outlook 2010, and it no longer works. It errors on the Dim rec as ADODB.record set line and gives a Compile Error: User-defined type not defined.
Any ideas what I need to change to get this to work in Outlook 2010?
Public Sub UpdateContactPhoto()
Dim myOlApp As Outlook.Application
Dim myNamespace As Outlook.Namespace
Dim myContacts As Outlook.Items
Dim myItems As Outlook.Items
Dim myItem As Object
Set myOlApp = CreateObject("Outlook.Application")
Set myNamespace = myOlApp.GetNamespace("MAPI")
Set myContacts = myNamespace.Folders.Item("Mailbox - Thomas, Susan"). _
Folders.Item("Temp Contacts").Items
Dim fs As Object
Set fs = CreateObject("Scripting.FileSystemObject")
For Each myItem In myContacts
If (myItem.Class = olContact) Then
Dim myContact As Outlook.ContactItem
Set myContact = myItem
Dim strPhoto As String
Dim rec As ADODB.Recordset
Dim strSQL As String
strSQL = "SELECT abcdefg from 123456 Where FullName = '" & myItem & "'"
Set con = New ADODB.Connection
con.Open = "Provider=SQLOLEDB;Data Source=ABC;Initial Catalog=XYZ;User ID=867;Password=5309;"
Set rec = con.Execute(strSQL)
If Not rec.EOF Then
TheValue = rec.Fields(3).Value
strPhoto = "\\picserver\EmployeePics\" & TheValue
If fs.FileExists(strPhoto) Then
myContact.AddPicture strPhoto
myContact.Save
End If
End If
Else
End If
Next
End Sub