Results 1 to 3 of 3

Thread: getting data from outlook contact

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Posts
    2

    Exclamation

    Hi, I have this strange problem. I can get the data from outlook 2000 but i can't get the data out of "set" the variables without an run-time 91 error.



    Private Sub Command1_Click()
    Dim Number, PhoneNumber As String
    Number = "40568886"

    If Len(Number) = 8 Then
    PhoneNumber = """+45 " & Mid$(Number, 1, 2) & " " & Mid$(Number, 3, 2) & " " & Mid$(Number, 5, 2) & " " & Mid$(Number, 7, 2) & """"
    End If


    Set myOlApp = CreateObject("Outlook.Application")
    Set myNameSpace = myOlApp.GetNamespace("MAPI")
    Set mycontacts = myNameSpace.GetDefaultFolder(olFolderContacts)
    Set myhomephone = mycontacts.Items.Find("[HomeTelephoneNumber] = " & PhoneNumber)
    Set myBusinessPhone = mycontacts.Items.Find("[BusinessTelephoneNumber] = " & PhoneNumber)
    Set myMobilePhone = mycontacts.Items.Find("[MobileTelephoneNumber] = " & PhoneNumber)

    If myhomephone = "" Then Exit Sub


  2. #2

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Posts
    2

    Variables

    Do any one know what kind og variables the outlook "set" variables are??

    Mogens

  3. #3
    Lively Member
    Join Date
    Mar 2000
    Posts
    87
    Try this code. One thing to keep in mind, is that to find a match on the phone number requires it to be same as the formatting in outlook. So if you search for 1234567 and its formatted at (12) 345 67 you wont find a match.

    Code:
    Public Sub MatchPhoneNumbers(ByVal PhoneNumber As String)
    
        Dim objApplication      As Application
        Dim objNameSpace        As NameSpace
        Dim objContacts         As MAPIFolder
        Dim objContact          As ContactItem
    
        Set objApplication = CreateObject("Outlook.Application")
        If Not objApplication Is Nothing Then
            Set objNameSpace = objApplication.GetNamespace("MAPI")
            If Not objNameSpace Is Nothing Then
                Set objContacts = objNameSpace.GetDefaultFolder(olFolderContacts)
                If Not objContacts Is Nothing Then
                    Set objContact = objContacts.Items.Find("[MobileTelephoneNumber] = '" & PhoneNumber & "' OR " & _
                                                         "[BusinessTelephoneNumber] = '" & PhoneNumber & "' OR " & _
                                                         "[HomeTelephoneNumber] = '" & PhoneNumber & "'")
                    If objContact Is Nothing Then
                        MsgBox "Couldnt find contact"
                    Else
                        MsgBox "Home Phone=" & objContact.HomeTelephoneNumber & vbCrLf & _
                            "Business Phone=" & objContact.BusinessTelephoneNumber & vbCrLf & _
                            "Mobile Phone=" & objContact.MobileTelephoneNumber
                    End If
                End If
            End If
        End If
    
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width