Outlook 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
 
J

Jean-Guy Marcil

Kerry was telling us:
Kerry nous racontait que :
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"

Sandwich you userform list filling code in an If statement:

If oItm.Class = 40 Then '40 = contactItem 69 = DistribListItem
With Me.RecipList
'etc.
End With
End If

By the way, why did you comment out the variable declaration block?
I wouldn't...
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

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
K

Kerry

Hi Jean-Guy

Thank you very much for the info, I have tried it out but
I am still getigng an error message when distribution
lists are present - have I entered the code correctly??

'recipient:

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

For Each oItm In oNspc.GetDefaultFolder
(olFolderContacts).Items
If oItm.Class = 40 Then '40 = contactItem 69 =
DistribListItem
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
 
J

Jean-Guy Marcil

Kerry was telling us:
Kerry nous racontait que :
Hi Jean-Guy

Thank you very much for the info, I have tried it out but
I am still getigng an error message when distribution
lists are present - have I entered the code correctly??

From the snippet you have posted, I would say yes.
I have used that before without any problems, so from where I am sitting, I
can't say why it is not working for you.
What lines errors out now? What is the error message (Same as before or
not)?

Have you posted in an Outlook group?
If you do and get an answer, report back!
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
K

Kerry

Hi Jean-Guy

I am still getting the same error as before - data type
mismatch error 13. the error does not appear and all
works well if I remove all distribution lists from my
outlook contacts area

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

For Each oItm In oNspc.GetDefaultFolder
(olFolderContacts).Items
If oItm.Class = 40 Then '40 = contactItem 69 =
DistribListItem
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
End If
x = x + 1
Next oItm

I have posted this in the Outlook area too (Word
connectivity). I received a different answer, but still
the same error when distribution lists are present.

I am puzzled-have u any other ideas please?? Thank you
very much

Kerry.
 
K

Kerry

Hi Jean-Guy

The answer to my Word Connection question posted in the
Outlook Newsgroup works wonderfully - I had missed the
changed variable declaration - dim OItm as Object not
ContactItem

Thanks very much

Kerry
 
J

Jean-Guy Marcil

Kerry was telling us:
Kerry nous racontait que :
Hi Jean-Guy

The answer to my Word Connection question posted in the
Outlook Newsgroup works wonderfully - I had missed the
changed variable declaration - dim OItm as Object not
ContactItem

Ha, right!
That's what I had done as well... overlooked that small important detail in
my previous post!
Sorry about that!

I think it is a bug of some sort because, according to Outlook VBA help, the
Class property applies to a ContactItem object, but for the code to work,
you have to declare it as a generic object.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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

Word Connection 3
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
Error handling for missing Outlook attachments 1

Top