0

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
SeanC
  • 15,695
  • 5
  • 45
  • 66
Susan T.
  • 21
  • 1
  • 8

1 Answers1

0

In the code editor, you need to add the reference to the ADODB library.

Go to the Tools -> References menu
access menu

and search for the Microsoft ActiveX Data Objects x.x Library - Note that the version number will change depending on which version is loaded on your machine

references

SeanC
  • 15,695
  • 5
  • 45
  • 66
  • I see where to do this now in Tools | References, but how do I determine which version is loaded on my machine? Do you mean what version of Outlook is on my machine? – Susan T. Apr 03 '13 at 17:09
  • the version of the ActiveX Data Objects – SeanC Apr 03 '13 at 17:51
  • Thanks for your help. I needed to add Active X. I must have done that before, and forgot all about it. – Susan T. Apr 03 '13 at 18:42