Word Connection

K

Kerry

Hi

I have created a user form which displays a list of my
outlook contacts. These contact details are then used
for addressing letters, labels, memos etc. this works
wonderfully unless I have distribution lists in my
outlook contacts area - it will then show "Runtime error
13 - type mismatch"

Please, how can I get my contact drop down list in my
user form to not display distribution lists and not crash
either.

Thanks very much.

Kerry

Public Sub UserForm_Initialize()
' Dim oApp As Outlook.Application
' Dim oNspc As NameSpace
' Dim oItm As ContactItem
' Dim x As Integer
' Dim y As Integer

Dim myLocation

If Not Application.DisplayStatusBar Then
Application.DisplayStatusBar = True
End If
StatusBar = "Please Wait....."

recipient:
x = 0
Set oApp = CreateObject("Outlook.Application")
Set oNspc = oApp.GetNamespace("MAPI")

For Each oItm In oNspc.GetDefaultFolder
(olFolderContacts).Items
With Me.RecipList
.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 = "Ready..."
Set oItm = Nothing
Set oNspc = Nothing
Set oApp = Nothing

myLocation = System.ProfileString("ML", "Location")

Select Case myLocation
Case "birmingham"
BirmOpt = True
Case "london"
LonOpt = True
Case "wokingham"
WokOpt = True

End Select

Sender1.Caption = System.ProfileString("ML", "Sender1")
Sender2.Caption = System.ProfileString("ML", "Sender2")
Sender3.Caption = System.ProfileString("ML", "Sender3")
Sender4.Caption = System.ProfileString("ML", "Sender4")

End Sub
 
K

Ken Slovak - [MVP - Outlook]

Public Sub UserForm_Initialize()
Dim oApp As Outlook.Application
Dim oNspc As Outlook.NameSpace
Dim oItm As Object
Dim x As Integer
Dim y As Integer

Dim myLocation

If Not Application.DisplayStatusBar Then
Application.DisplayStatusBar = True
End If
StatusBar = "Please Wait....."

recipient:
x = 0
Set oApp = CreateObject("Outlook.Application")
Set oNspc = oApp.GetNamespace("MAPI")

For Each oItm In _
oNspc.GetDefaultFolder(olFolderContacts).Items

If oItm.Class = olContact Then 'no DL used
With Me.RecipList
.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
End If
Next oItm

StatusBar = "Ready..."
Set oItm = Nothing
Set oNspc = Nothing
Set oApp = Nothing

myLocation = System.ProfileString("ML", "Location")

Select Case myLocation
Case "birmingham"
BirmOpt = True
Case "london"
LonOpt = True
Case "wokingham"
WokOpt = True

End Select

Sender1.Caption = System.ProfileString("ML", "Sender1")
Sender2.Caption = System.ProfileString("ML", "Sender2")
Sender3.Caption = System.ProfileString("ML", "Sender3")
Sender4.Caption = System.ProfileString("ML", "Sender4")

End Sub
 
K

Kerry

Hi Ken

Thanks for the information. I have entered the code
exactly as you recommended, I am still getting the data
type mismatch error 13 when distribution lists are
present, no errors if there are only standard contacts.
Is there anything else I could be missing?

Many Thanks

Kerry
 
K

Ken Slovak - [MVP - Outlook]

Looks OK. On what line are you getting the error? have you tried stepping
your code?
 

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

Outlook Connection 6
Combo Box 1
Combo Box 0
Contacts 2
Outlook Connection 1
Accessing Contact subfolders with a VBA macro 1
Working with non-default folders in VBA 2
open custom form 3

Top