Combo Box

K

Kerry

I have created a Word User form which lists all of my
Outlook Contacts.

How can I sort the combo box - at the moment it is sorting
the names by the order in which they were created in
Outlook!!

Once this is sorted, my work is done!!

Thanks in advance.

Please find a copy of my code below:-

Private Sub UserForm_Initialize()
Dim oApp As Outlook.Application
Dim oNspc As NameSpace
Dim oItm As ContactItem
Dim x As Integer
Dim y As Integer
If Not DisplayStatusBar Then
DisplayStatusBar = True
End If
StatusBar = "Please Wait....."
sender:
x = 0
Set oApp = CreateObject("Outlook.Application")
Set oNspc = oApp.GetNamespace("MAPI")
For Each oItm In oNspc.GetDefaultFolder
(olFolderContacts).Items
With Me.cboContactList
.AddItem (oItm.FullName)
.Column(1, x) = oItm.JobTitle
.Column(2, x) = oItm.CompanyName
.Column(3, x) = oItm.BusinessAddress
.Column(4, x) = oItm.BusinessTelephoneNumber
.Column(5, x) = oItm.BusinessFaxNumber

End With
x = x + 1
Next oItm
StatusBar = ""
Set oItm = Nothing
Set oNspc = Nothing
Set oApp = Nothing
recipient:
y = 0
Set oApp = CreateObject("Outlook.Application")
Set oNspc = oApp.GetNamespace("MAPI")
For Each oItm In oNspc.GetDefaultFolder
(olFolderContacts).Items
With Me.cboContactList2
.AddItem (oItm.FullName)
.Column(1, y) = oItm.JobTitle
.Column(2, y) = oItm.CompanyName
.Column(3, y) = oItm.BusinessAddress
.Column(4, y) = oItm.BusinessTelephoneNumber
.Column(5, y) = oItm.BusinessFaxNumber

End With
y = y + 1
Next oItm
StatusBar = ""
Set oItm = Nothing
Set oNspc = Nothing
Set oApp = Nothing
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Combo Box 1
Outlook Connection 6
Outlook Connection 1
Contacts 2
Word Connection 3
Adding Contact with VBA 4
Accessing Contact subfolders with a VBA macro 1
Working with non-default folders in VBA 2

Top