VB & OutLook Address Book

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ken OHanlon
    New Member
    • Apr 2008
    • 39

    #1

    VB & OutLook Address Book

    I found this proven VB code on the internet, copy/pasted it but I get a "Method or data member not found" error on the line SET OLA=APPLICATION .SESSION... What am I doing wrong? Thanks -Ken.

    Only needs "Microsoft Outlook xx.x Object Library - I used 11.0)
    Code:
    Private Sub cmdAddress_Book_Click()
       '---- create an listbox (I named it ab - Address Book)
       Dim ola As Outlook.AddressList
       Dim ole As Outlook.AddressEntry
    
       On Error Resume Next
       Set ola = Application.Session.AddressLists("Contacts") 
       For Each ole In ola.AddressEntries
           ab.AddItem ole
       Next
       Set ola = Nothing
       Set ole = Nothing
    End Sub
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by Ken OHanlon
    I found this proven VB code on the internet, copy/pasted it but I get a "Method or data member not found" error on the line SET OLA=APPLICATION .SESSION... What am I doing wrong? Thanks -Ken.

    Only needs "Microsoft Outlook xx.x Object Library - I used 11.0)
    Private Sub cmdAddress_Book _Click()
    '---- create an listbox (I named it ab - Address Book)
    Dim ola As Outlook.Address List
    Dim ole As Outlook.Address Entry

    On Error Resume Next
    Set ola = Application.Ses sion.AddressLis ts("Contacts")
    For Each ole In ola.AddressEntr ies
    ab.AddItem ole
    Next
    Set ola = Nothing
    Set ole = Nothing
    End Sub
    I can't see how this code would ever work, since you have not fully qualified the Outlook Application Object. The code fails on this line because it expects to find a Method or Property of the Access Application Object, not Outlook, named Session. Of course this Property/Method does not exist. Once you indicate that you are explicitly referring to the Outlook Application Object (Lines 6 and 10), then then Session is a valid Property, and the code should now execute correctly. Be advised that I had no actual way of testing this Theory, I'm just assuming that it is correct.
    [CODE=vb]
    '---- create an listbox (I named it ab - Address Book)
    Dim outApp As Outlook.Applica tion
    Dim ola As Outlook.Address List
    Dim ole As Outlook.Address Entry

    Set outApp = New Outlook.Applica tion

    On Error Resume Next

    Set ola = outApp.Session. AddressLists("C ontacts")

    For Each ole In ola.AddressEntr ies
    ab.AddItem ole
    Next

    outApp.Close

    Set outApp = Nothing
    Set ola = Nothing
    Set ole = Nothing[/CODE]

    Comment

    • Ken OHanlon
      New Member
      • Apr 2008
      • 39

      #3
      Originally posted by ADezii
      I can't see how this code would ever work, since you have not fully qualified the Outlook Application Object. The code fails on this line because it expects to find a Method or Property of the Access Application Object, not Outlook, named Session. Of course this Property/Method does not exist. Once you indicate that you are explicitly referring to the Outlook Application Object (Lines 6 and 10), then then Session is a valid Property, and the code should now execute correctly. Be advised that I had no actual way of testing this Theory, I'm just assuming that it is correct.
      [CODE=vb]
      '---- create an listbox (I named it ab - Address Book)
      Dim outApp As Outlook.Applica tion
      Dim ola As Outlook.Address List
      Dim ole As Outlook.Address Entry

      Set outApp = New Outlook.Applica tion

      On Error Resume Next

      Set ola = outApp.Session. AddressLists("C ontacts")

      For Each ole In ola.AddressEntr ies
      ab.AddItem ole
      Next

      outApp.Close

      Set outApp = Nothing
      Set ola = Nothing
      Set ole = Nothing[/CODE]

      Oh great one, You are correct. My next problem is that the for/next loop finds nothing to add. Is the actual name of MS OutLook Express address book called "Contacts"? I tried Contacts, MyContacts, and even some junk like DFGOIJEGUG and I keep getting the same result. Thanks -Ken.

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        Originally posted by Ken OHanlon
        Oh great one, You are correct. My next problem is that the for/next loop finds nothing to add. Is the actual name of MS OutLook Express address book called "Contacts"? I tried Contacts, MyContacts, and even some junk like DFGOIJEGUG and I keep getting the same result. Thanks -Ken.
        Again, I have no way to test this, but the following code should list all the entries in the Outlook Address Book, and Print them to the Immediate Window, I think (LOL).
        [CODE=vb]
        Dim outApp As Outlook.Applica tion
        Dim ola As Outlook.Address List
        Dim intCounter As Integer

        Set outApp = New Outlook.Applica tion

        On Error Resume Next

        For intCounter = 1 To outApp.Session. AddressLists.Co unt
        Debug.Print "Address List Entry #" & intCounter & ": " & _
        outApp.Session. AddressLists(in tCounter).Name
        Next

        Set outApp = Nothing
        Set ola = Nothing
        Set ole = Nothing[/CODE]

        Comment

        • Ken OHanlon
          New Member
          • Apr 2008
          • 39

          #5
          Originally posted by ADezii
          Again, I have no way to test this, but the following code should list all the entries in the Outlook Address Book, and Print them to the Immediate Window, I think (LOL).
          [CODE=vb]
          Dim outApp As Outlook.Applica tion
          Dim ola As Outlook.Address List
          Dim intCounter As Integer

          Set outApp = New Outlook.Applica tion

          On Error Resume Next

          For intCounter = 1 To outApp.Session. AddressLists.Co unt
          Debug.Print "Address List Entry #" & intCounter & ": " & _
          outApp.Session. AddressLists(in tCounter).Name
          Next

          Set outApp = Nothing
          Set ola = Nothing
          Set ole = Nothing[/CODE]

          Oh great one, You are correct AGAIN. The address books name is "Global Address List" OutLook took noticed that I was looking at the address book because it put up a Window informing me that someone was trying to get to my address book and was that OK with me. "Contacts" never got a rise from OutLook!!! My same problem is still that the for/next loop finds nothing to add. Thanks -Ken.

          Comment

          • ADezii
            Recognized Expert Expert
            • Apr 2006
            • 8834

            #6
            Originally posted by Ken OHanlon
            Oh great one, You are correct AGAIN. The address books name is "Global Address List" OutLook took noticed that I was looking at the address book because it put up a Window informing me that someone was trying to get to my address book and was that OK with me. "Contacts" never got a rise from OutLook!!! My same problem is still that the for/next loop finds nothing to add. Thanks -Ken.
            BTW, thanks but absolutely no need for the great one reference. Try these 2 approaches to the problem, and see which, if either one, works:
            [CODE=vb]
            '---- create an listbox (I named it ab - Address Book)
            Dim outApp As Outlook.Applica tion
            Dim ola As Outlook.Address List
            Dim ole As Outlook.Address Entry
            Dim intNumOfEntries As Integer

            Set outApp = New Outlook.Applica tion

            On Error Resume Next

            Set ola = outApp.Session. AddressLists("G lobal Address List")

            'Try this method first
            For Each ole In ola.AddressEntr ies
            Me![ab].AddItem ole.Name
            Next

            'Try this Method if the first does not work
            For intNumOfEntries = 1 To ola.AddressEntr ies.Count
            Me![ab].AddItem ola.AddressEntr ies(intNumOfEnt ries).Name
            Next

            Set outApp = Nothing
            Set ola = Nothing
            Set ole = Nothing[/CODE]
            NOTE: I'm assuming you have either a List or Combo Box named ab on the Active Form and that you are using Access 2002 or greater in order to use the AddItem Method. Are these references True?

            Comment

            • Ken OHanlon
              New Member
              • Apr 2008
              • 39

              #7
              Originally posted by ADezii
              BTW, thanks but absolutely no need for the great one reference. Try these 2 approaches to the problem, and see which, if either one, works:
              [CODE=vb]
              '---- create an listbox (I named it ab - Address Book)
              Dim outApp As Outlook.Applica tion
              Dim ola As Outlook.Address List
              Dim ole As Outlook.Address Entry
              Dim intNumOfEntries As Integer

              Set outApp = New Outlook.Applica tion

              On Error Resume Next

              Set ola = outApp.Session. AddressLists("G lobal Address List")

              'Try this method first
              For Each ole In ola.AddressEntr ies
              Me![ab].AddItem ole.Name
              Next

              'Try this Method if the first does not work
              For intNumOfEntries = 1 To ola.AddressEntr ies.Count
              Me![ab].AddItem ola.AddressEntr ies(intNumOfEnt ries).Name
              Next

              Set outApp = Nothing
              Set ola = Nothing
              Set ole = Nothing[/CODE]
              NOTE: I'm assuming you have either a List or Combo Box named ab on the Active Form and that you are using Access 2002 or greater in order to use the AddItem Method. Are these references True?

              I am using XP, Access 2003, and a List Box. When you helped me find the name of the OutLook Address Book, I only got one NAME back from that routine("Global Address List"). I was always wondering why I had not gotten more NAME's because I have several folders of e-mail addresses. "ola.AddressEnt ries.Count" = 0. Apparently I found an Address Book but its empty? Thanks -Ken.

              Comment

              • Ken OHanlon
                New Member
                • Apr 2008
                • 39

                #8
                Originally posted by Ken OHanlon
                I am using XP, Access 2003, and a List Box. When you helped me find the name of the OutLook Address Book, I only got one NAME back from that routine("Global Address List"). I was always wondering why I had not gotten more NAME's because I have several folders of e-mail addresses. "ola.AddressEnt ries.Count" = 0. Apparently I found an Address Book but its empty? Thanks -Ken.
                Everytime I mention OutLook, I am talking about OutLook Express. Is this my problem all along? Ken

                Comment

                • ADezii
                  Recognized Expert Expert
                  • Apr 2006
                  • 8834

                  #9
                  Originally posted by Ken OHanlon
                  Everytime I mention OutLook, I am talking about OutLook Express. Is this my problem all along? Ken
                  I honestly cannot say one way or the other, Ken.

                  Comment

                  Working...