|
-
Oct 11th, 2005, 05:09 AM
#1
Thread Starter
Addicted Member
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?
-
Oct 11th, 2005, 07:39 AM
#2
Re: Global address book names in a list view
Try this...
VB Code:
Private olApp As Outlook.Application
Private olNS As Outlook.NameSpace
Private olAL As Outlook.AddressList
Private olAE As Outlook.AddressEntry
Private Sub Form_Load()
Dim Counter As Long
Set olApp = New Outlook.Application
Set olNS = olApp.GetNamespace("MAPI")
For Each olAL In olNS.AddressLists
For Each olAE In olAL.AddressEntries
DoEvents
Counter = Counter + 1
Label1.Caption = Counter
ListView1.ListItems.Add , , olAE.Name
ListView1.ListItems(ListView1.ListItems.Count).SubItems(1) = olAE.Address
Next
Next
End Sub
-
Oct 11th, 2005, 08:38 AM
#3
Thread Starter
Addicted Member
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.
-
Oct 11th, 2005, 08:43 PM
#4
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Oct 12th, 2005, 11:48 PM
#5
Thread Starter
Addicted Member
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.
-
Oct 14th, 2005, 02:49 AM
#6
Junior Member
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...
-
Oct 16th, 2005, 05:49 PM
#7
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Oct 17th, 2005, 01:30 AM
#8
Thread Starter
Addicted Member
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?
-
Oct 17th, 2005, 07:17 AM
#9
Thread Starter
Addicted Member
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...
-
Oct 18th, 2005, 04:47 AM
#10
Thread Starter
Addicted Member
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).
-
Oct 18th, 2005, 09:56 AM
#11
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|