Google Answers Logo
View Question
 
Q: Office XP, VBA access to City field ( Answered 3 out of 5 stars,   0 Comments )
Question  
Subject: Office XP, VBA access to City field
Category: Computers > Programming
Asked by: whychild-ga
List Price: $25.00
Posted: 11 Nov 2002 10:11 PST
Expires: 11 Dec 2002 10:11 PST
Question ID: 105331
I want to iterate through my contacts and modify the City (and other
fields).

I have tried this...
Sub showEntryAttrib()
    Set myOlApp = CreateObject("Outlook.Application")
    Set myNamespace = myOlApp.GetNamespace("MAPI")
        For Each one In myNamespace.AddressLists
            Debug.Print one.Name
            For Each two In one.AddressEntries
                Debug.Print "   " + two.Address
                Debug.Print "   " + two.HomeAddressCity
            Next
        Next
        Set myOlApp = Nothing
        Set myNamespace = Nothing

End Sub
...
but it throws an error on HomeAddressCity, (two.address works)
I'm thinking I need to access the "Contacts" folder and then iterate
through contacts there, but the doc is thin....

Request for Question Clarification by hammer-ga on 11 Nov 2002 11:06 PST
As what have you declared "one" and "two"?

Clarification of Question by whychild-ga on 11 Nov 2002 11:43 PST
I didnt explicitly declare, by default 
one is a nameSpace
two is a addressList
Answer  
Subject: Re: Office XP, VBA access to City field
Answered By: hammer-ga on 11 Nov 2002 12:20 PST
Rated:3 out of 5 stars
 
This Microsoft Knowledge Base article includes an example of doing
this by accessing the Default Contacts folder:
http://support.microsoft.com/default.aspx?scid=kb;en-us;181202

----------------------------
Here is an example posted to a newsgroup:

    Dim olApp As New Application
    Dim MsgDataStore As NameSpace
    Dim MsgPersonalFolders As Folders
    Dim MsgContactFolder As MAPIFolder
    Dim itm As ContactItem
    Dim str As String

    Set MsgDataStore = olApp.GetNamespace("MAPI")
    Set MsgPersonalFolders = MsgDataStore.Folders("Personal
Folders").Folders
    Set MsgContactFolder = MsgPersonalFolders("Contacts")
    For Each itm In MsgContactFolder.Items
        str = ""
        str = str & itm.FirstName & vbCrLf
        str = str & itm.LastName & vbCrLf
        str = str & itm.Email1Address & vbCrLf
        str = str & itm.HomeAddressCity & vbCrLf
        str = str & itm.HomeAddressState & vbCrLf
    Next itm

There are other examples, but this one seems clearest. As you can see,
you are right about accessing the Contacts folder.

Google Groups Search Terms: Outlook VB HomeAddressCity
----------------------

This page has an interesting set of code samples for working with
Outlook:
http://www.helenfeddema.com/CodeSamples.htm#Code40

Here is a article showing some advanced techniques for working with
the Outlook Object Model:
http://www.fawcette.com/vsm/2002_09/magazine/columns/gettingstarted/default.asp

Good luck with your project!

- Hammer

Clarification of Answer by hammer-ga on 12 Nov 2002 07:24 PST
Just for future reference, if you request clarification before rating
an answer, the Researcher will usually be glad to try to provide
additional information. In this case, if you had let me know what the
trouble was with the examples provided, I may have been able to locate
more specific information.

- Hammer
whychild-ga rated this answer:3 out of 5 stars
Found an example, but I had to hack it to make it run.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy