Share via


Edit an Account

Outlook Developer Reference
Edit an Account

To edit an Account object programmatically, do the following:

  1. Select the object.
  2. Assign new values to those properties that you want to modify.
  3. Invoke the Save method on the object to save the changes.

The following C# and Visual Basic for Applications (VBA) example shows how to edit an Account object.

  private void EditAccount()
{ 

Outlook.ApplicationClass _app = new Outlook.ApplicationClass(); Outlook.Application olApp = (Outlook.Application)_app; Outlook.NameSpace olNameSpace = _app.GetNamespace("MAPI"); Outlook.Folders folders = olNameSpace.Session.Folders; Outlook.Folder bcmRootFolder = (Outlook.Folder)folders["Business Contact Manager"]; Outlook.Folder accountsFolder = (Outlook.Folder)bcmRootFolder.Folders["Accounts"];

string strQuery = "[FileAs] = 'Wide World Importers'";

Outlook.ContactItem accountItem = (Outlook.ContactItem)accountsFolder.Items.Find(strQuery); if (accountItem != null) { accountItem.BusinessAddressCity = "New City Address"; accountItem.BusinessAddressState = "New Address State"; accountItem.BusinessAddressStreet = "New Address Street"; accountItem.Save(); }

else {

  Console.WriteLine("Account not found"); 

}

}

  Sub EditAccount()

Dim olApp As Outlook.Application Dim objNS As Outlook.NameSpace Dim bcmRootFolder As Outlook.Folder Dim olFolders As Outlook.Folders Dim bcmAccountsFldr As Outlook.Folder Dim existAcct As Outlook.ContactItem

Set olApp = CreateObject("Outlook.Application") Set objNS = olApp.GetNamespace("MAPI") Set olFolders = objNS.Session.Folders Set bcmRootFolder = olFolders("Business Contact Manager") Set bcmAccountsFldr = bcmRootFolder.Folders("Accounts") Set existAcct = bcmAccountsFldr.Items.Find("[FileAs] = 'Wide World'")

If Not TypeName(existAcct) = "Nothing" Then

  existAcct.BusinessAddressCity = "New City Address"
  existAcct.BusinessAddressState = "New Address State"
  existAcct.BusinessAddressStreet = "New Address Street"
  existAcct.Save

Else

  MsgBox ("No account found with Full Name Wide World Importers")

End If

Set existAcct = Nothing Set bcmAccountsFldr = Nothing Set olFolders = Nothing Set bcmRootFolder = Nothing Set objNS = Nothing Set olApp = Nothing

End Sub

See Also

Create an Account | Select an Account | Delete an Account | Office Developer Center: Outlook 2007