Trying to set the way contacts are stored via FileAs 
Author Message
 Trying to set the way contacts are stored via FileAs

Trying to set the way contacts are stored via FileAs.

Here is my code - it is a quick Macro I wrote, but it does not update the
contact?
I am using Outlook 2000.

Thanks for any help.  Chris

Public Sub CorrectContacts()

Dim ofContacts As MAPIFolder
Dim oicItems As Items
Dim ocContact As ContactItem
Dim i As Integer
Dim sFirstName As String
Dim sLastName As String
Dim sCompanyName As String

Set ofContacts =
Application.GetNamespace("MAPI").GetDefaultFolder(olFolderContacts)
Set oicItems = ofContacts.Items

'Set ocContact = oicItems.Item(1)

Open "C:\CorrectContacts.txt" For Output As #1

Print #1, "***********************************************"

For i = 1 To ofContacts.Items.Count
    If Left(oicItems.Item(i), 1) = "*" Then
        Print #1, "Skip Item: " & oicItems.Item(i)
        Debug.Print "Skip Item: " & oicItems.Item(i)
    Else
        sFirstName = Trim(oicItems.Item(i).FirstName)
        sLastName = Trim(oicItems.Item(i).LastName)
'        Debug.Print "*********************************"
        If sFirstName = "" And sLastName = "" Then
            ' use company name
            sCompanyName = Trim(oicItems.Item(i).CompanyName)
            If sCompanyName = "" Then
                ' skip - not sure what to do
'                Debug.Print "Skip Item (because no first, last, or company
name found): " & oicItems.Item(i)
            Else
                ' use the company name - in the FileAs
                Print #1, "File Contact As: " & sCompanyName
                oicItems.Item(i).FileAs = sCompanyName
            End If
        Else
            If sLastName = "" Then
                ' use first name
                Print #1, "File Contact As: " & sFirstName
                oicItems.Item(i).FileAs = sFirstName
            Else
                If sFirstName = "" Then
                    ' only store the last name
                    Print #1, "File Contact As: " & sLastName
                    oicItems.Item(i).FileAs = sLastName
                Else
                    ' store both the last name and first name
                    sFirstName = sLastName & ", " & sFirstName
                    Print #1, "File Contact As: " & sFirstName
                    'oicItems.Item(i).UserProperties("[FileAs]") =
sFirstName
                    oicItems.Item(i).FileAs = sFirstName
                    'oicItems.Item(i).FileAs = sFirstName & ", " & sLastName
                End If
            End If
        End If
        oicItems.Item(i).Save
    End If
Next i

Print #1, "***********************************************"
Close #1

Set ofContacts = Nothing
Set oicItems = Nothing

MsgBox "Finished -- For a report open file: C:\CorrectContacts.txt"

End Sub



Fri, 21 Jun 2002 03:00:00 GMT  
 Trying to set the way contacts are stored via FileAs
Found my problem..  -- The code I was using works only if you want to read
the value of the contact item.  If you want to set the value of the contact
item "FileAs"
I found you have to do the following.

Dim ocContact As ContactItem

For i = 1 To ofContacts.Items.Count

 Set ocContact = oicItems.Item(i)

 FirstName = oicItems.Item(i).FirstName

 ocContact.FileAs = sLastName & ", " & sFirstName


Quote:
> Trying to set the way contacts are stored via FileAs.

> Here is my code - it is a quick Macro I wrote, but it does not update the
> contact?
> I am using Outlook 2000.

> Thanks for any help.  Chris

> Public Sub CorrectContacts()

> Dim ofContacts As MAPIFolder
> Dim oicItems As Items
> Dim ocContact As ContactItem
> Dim i As Integer
> Dim sFirstName As String
> Dim sLastName As String
> Dim sCompanyName As String

> Set ofContacts =
> Application.GetNamespace("MAPI").GetDefaultFolder(olFolderContacts)
> Set oicItems = ofContacts.Items

> 'Set ocContact = oicItems.Item(1)

> Open "C:\CorrectContacts.txt" For Output As #1

> Print #1, "***********************************************"

> For i = 1 To ofContacts.Items.Count
>     If Left(oicItems.Item(i), 1) = "*" Then
>         Print #1, "Skip Item: " & oicItems.Item(i)
>         Debug.Print "Skip Item: " & oicItems.Item(i)
>     Else
>         sFirstName = Trim(oicItems.Item(i).FirstName)
>         sLastName = Trim(oicItems.Item(i).LastName)
> '        Debug.Print "*********************************"
>         If sFirstName = "" And sLastName = "" Then
>             ' use company name
>             sCompanyName = Trim(oicItems.Item(i).CompanyName)
>             If sCompanyName = "" Then
>                 ' skip - not sure what to do
> '                Debug.Print "Skip Item (because no first, last, or
company
> name found): " & oicItems.Item(i)
>             Else
>                 ' use the company name - in the FileAs
>                 Print #1, "File Contact As: " & sCompanyName
>                 oicItems.Item(i).FileAs = sCompanyName
>             End If
>         Else
>             If sLastName = "" Then
>                 ' use first name
>                 Print #1, "File Contact As: " & sFirstName
>                 oicItems.Item(i).FileAs = sFirstName
>             Else
>                 If sFirstName = "" Then
>                     ' only store the last name
>                     Print #1, "File Contact As: " & sLastName
>                     oicItems.Item(i).FileAs = sLastName
>                 Else
>                     ' store both the last name and first name
>                     sFirstName = sLastName & ", " & sFirstName
>                     Print #1, "File Contact As: " & sFirstName
>                     'oicItems.Item(i).UserProperties("[FileAs]") =
> sFirstName
>                     oicItems.Item(i).FileAs = sFirstName
>                     'oicItems.Item(i).FileAs = sFirstName & ", " &
sLastName
>                 End If
>             End If
>         End If
>         oicItems.Item(i).Save
>     End If
> Next i

> Print #1, "***********************************************"
> Close #1

> Set ofContacts = Nothing
> Set oicItems = Nothing

> MsgBox "Finished -- For a report open file: C:\CorrectContacts.txt"

> End Sub



Sat, 22 Jun 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Problem with FileAs and middle name in contacts (OL2000)

2. tried to store data in a custom contact form

3. I am trying to set the state of the keyboard LEDs from within VB.

4. I am trying to update a record, i am not using data control

5. I am trying to update a record, i am not using data control

6. Finding Printer Information via ADSI or other ways?

7. Trying to import Outlook Contacts on Computer

8. I am trying to connect ot forms using Access 2002

9. What am I trying to do?

10. Trying to connect to a Contacts Folder

11. I am trying igain - somebody must know

12. Trying to contact Eric Schonning (csun.edu)

 

 
Powered by phpBB® Forum Software