Results 1 to 11 of 11

Thread: Global address book names in a list view

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    151

    Global address book names in a list view

    I want all(FirstName LastName) from global address book in a listview :

    Firstname LastName


    anyone has the solution?

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Global address book names in a list view

    Try this...
    VB Code:
    1. Private olApp As Outlook.Application
    2. Private olNS As Outlook.NameSpace
    3. Private olAL As Outlook.AddressList
    4. Private olAE As Outlook.AddressEntry
    5.  
    6. Private Sub Form_Load()
    7. Dim Counter As Long
    8. Set olApp = New Outlook.Application
    9.   Set olNS = olApp.GetNamespace("MAPI")
    10.   For Each olAL In olNS.AddressLists
    11.     For Each olAE In olAL.AddressEntries
    12.       DoEvents
    13.       Counter = Counter + 1
    14.       Label1.Caption = Counter
    15.       ListView1.ListItems.Add , , olAE.Name
    16.       ListView1.ListItems(ListView1.ListItems.Count).SubItems(1) = olAE.Address
    17.     Next
    18.   Next
    19. End Sub

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    151

    Re: Global address book names in a list view

    Getting error on this line:

    Code:
    ListView1.listitems(ListView1.listitems.Count).SubItems(1) = olAE.Address
    Run-time error-380

    Invalid property value

    Code is getting values(Checked with f8)

    Also this code is giving the alias of the member.
    I need FirstName and LastName
    Last edited by v_gyku; Oct 11th, 2005 at 09:25 AM.

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Global address book names in a list view

    Note, the AddressEntries is for your local AddressBook and not the Global Address List from Exchange. In my signature GAL example I use CDO 1.21 to retrieve the First and Last names in it and populate a listview.

    Did you add the reference to CDO 1.21?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    151

    Re: Global address book names in a list view

    Not in above code.
    But for your code i have included ref to cdo 1.21.

    I got following error :

    Run-time error'2147219963(80040605)
    Collaboration Data Objects-[MAP_E_Not_INITIALIZED(80040605)]]

    What i have to do if i want only firstname and lastname in a listview?
    Last edited by v_gyku; Oct 12th, 2005 at 11:52 PM.

  6. #6
    Junior Member
    Join Date
    Oct 2005
    Posts
    19

    Re: Global address book names in a list view

    I am trying to run your code.

    I have added ref to cdo 1.21, outlook 11.0
    I am using xp(outlook 2003)

    Application hangs up at this line :

    Code:
     Set oAEntries = moCDO.AddressLists.item("Global Address List").AddressEntries
        For i = 1 To oAEntries.Count
    I dont understand why your code is not running on my computer...

    Help me out...

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Global address book names in a list view

    You need to be running Outlook in an Exchange environment and have permissions to view the GAL.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    151

    Re: Global address book names in a list view

    I am able to get all the details of GAL in my outlook. I have this code(not mine) which takes display Firstname and lastname from GAL.

    Code:
    Private olApp As Outlook.Application
    Private olNS As Outlook.NameSpace
    Private olAL As Outlook.AddressList
    Private olAE As Outlook.AddressEntry
    Dim sName As String
    Dim arrName() As String
    Private Sub Command1_Click()
    On Error Resume Next
    'Private Sub UserControl_Initialize()
    Dim Counter As Long
    Dim listitems As ListItem
    Set olApp = New Outlook.Application
      Set olNS = olApp.GetNamespace("MAPI")
      For Each olAL In olNS.AddressLists
        For Each olAE In olAL.AddressEntries
          DoEvents
          sName = olAE.Name
          SplitName
          Set listitems = ListView1.listitems.Add
          listitems.Text = arrName(0) 'First name
          listitems.SubItems(1) = arrName(1) 'Last name
        Next
      Next
    End Sub
    
    Private Sub Form_Load()
    ListView1.View = lvwReport
    ListView1.ColumnHeaders.Add , , "First Name", 1500
    ListView1.ColumnHeaders.Add , , "Last Name", 1500
    End Sub
    
    Private Sub SplitName()
    
    'Split the name to first and last
    '--------------------------------
    arrName() = Split(sName, " ")
    
    End Sub
    So i dont think there is any problem with my exchnage server or Anything....

    Robdog can u tell me on which platform u r code is running....
    I AM WORKING ON WINDOWS XP(OFFICE 2003), EXCHAANGE SERVER 2003.
    Should your code run on my comp?

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    151

    Re: Global address book names in a list view

    Hello Sir !

    I have made certain changes in ur code and able to run it.

    Code:
     Dim oAEntries As AddressEntries
     Dim oAEntry As AddressEntry
     Dim oFields As Field
    Now i am getting the details in a listview.

    I am trying to take only Lastname,FirstName(In single column) in a listview or(it can be listbox also) and emailaddress as hidden field because i want email address of the seleted person. I am trying to write code for this with the help of your code but not getting the desired output...

    Can u guide me on this issue....

    Thanks...

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    151

    Re: Global address book names in a list view

    Hello !

    Its getting really difficult for me to get this....
    Code:
    Dim objoutlk As New Outlook.Application
    Dim fol As Outlook.mapiFolder
    Dim mapises As MAPI.Session
    Dim contact As Outlook.ContactItem
    Dim ns As Outlook.NameSpace
    Dim var1 As String
    Private Const cdoPR_GIVEN_NAME As Long = &H3A06001E
    Private Const cdoPR_SURNAME As Long = &H3A11001E
    Private Const cdoPR_EMAIL As Long = &H39FE001E
    
    Private Sub Form_Load()
    
    Set ns = objoutlk.GetNamespace("MApi")
    Set fol = ns.GetDefaultFolder(olFolderContacts)
    Me.Show
    For Each contact In fol.Items
        List1.AddItem contact.FirstName & " , " & contact.LastName
        
    Next
    Set mapises = CreateObject("MAPI.session")
    mapises.Logon "", "", False, False
    gal
    Set ns = Nothing
    Set objoutlk = Nothing
    Set fol = Nothing
    
    End Sub
    
    Public Sub gal()
    
        Dim oAEntries As AddressEntries
        Dim oAEntry As AddressEntry
        Dim oFields As Field
        Dim i As Integer
        Dim ii As Integer
        Dim iii As Integer
        Dim vDetails As Variant
        
    On Error GoTo errorfun
        Set oAEntries = mapises.AddressLists.Item("Global Address List").AddressEntries
        For i = 1 To oAEntries.Count
            Set oAEntry = oAEntries.Item(i)
            var1 = ""
            For ii = 1 To oAEntry.Fields.Count
            
                Set oFields = oAEntry.Fields(ii)
                vDetails = oFields.Value
                If oFields.ID = cdoPR_SURNAME Then
                    var1 = var1 & vDetails & " , "
                    
                ElseIf oFields.ID = cdoPR_GIVEN_NAME Then
                    var1 = var1 & vDetails
                    MsgBox var1
                    List1.AddItem var1
                End If
            Next
            
        Next
    errorfun:
    gal
    End Sub
    I am able to get firstname and lastname of all the contacts in a listbox.
    I want email ids of all of them.
    I am taking lastname,firstname in one column... Is there any way i can get emailid of all these in second column(which will be hidden).

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Global address book names in a list view

    If you look at my code example in my signature it shows how to get the email address too.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width