Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2004

Tip: Looking for answers? Try searching our database.

Outlook Connection

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Kerry - 23 Nov 2004 09:51 GMT
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
Jean-Guy Marcil - 23 Nov 2004 13:52 GMT
Kerry was telling us:
Kerry nous racontait que :

> Hi
>
[quoted text clipped - 4 lines]
> 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

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Kerry - 23 Nov 2004 15:11 GMT
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

>-----Original Message-----
>Kerry was telling us:
[quoted text clipped - 26 lines]
>> '    Dim x As Integer
>> '    Dim y As Integer
Jean-Guy Marcil - 23 Nov 2004 15:48 GMT
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!
Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Kerry - 23 Nov 2004 16:21 GMT
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.

>-----Original Message-----
>Kerry was telling us:
[quoted text clipped - 14 lines]
>Have you posted in an Outlook group?
>If you do and get an answer, report back!
Kerry - 23 Nov 2004 16:38 GMT
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

>-----Original Message-----
>Hi Jean-Guy
[quoted text clipped - 56 lines]
>>If you do and get an answer, report back!
>.
Jean-Guy Marcil - 23 Nov 2004 17:33 GMT
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.

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.