|
|
|||
| Code Essentials Printer Friendly Version | |||
|
|
Beginner’s section on how to work in the VBA environment, how to work with functions and expressions – generally not specific to Outlook | ||
| Topic | |||
|
|
Outlook 2010 with BCM: bcmContactsFldr.Items.Find("[FileAs] = 'Firstname Lastname'") Doesn't seem to work!
I reused some published code that was initially developped for Outlook 2007 with Business Contact Manager. The following statement in the code would result in setting the existContact to become the contact I am looking for. Set existContact = bcmContactsFldr.Items.Find("[FileAs] = 'Firstname Lastname'") I have changed this now into: Set existContact = bcmContactsFldr.Items("Firstname Lastname") And this does work when the contact is found, however it gives an error when the contact is NOT found so this is not an option either. Could anyone help me with some code to find a contact in Business Contact Manager 2010 based uppon the name of the person? Kind regards, Rick Stroot Rick Stroot 28-Jul-2010 17:01 |
||
|
|
Sue Mosher
28-Jul-2010 17:21
It doesn't work, because your search string doesn't tell Outlook what field to search in. That's the purpose of this portion of the search string: [FileAs] = You must include the name of the field whose data you want to search. |
||
|
|
Rick Stroot
29-Jul-2010 04:24
I thought I had specified the field in first line that I showed. However the problem is that it did work in Outlook 2007 but I can't get this to work in Outlook 2010. I have used a slightly different field being [FullName] =, but that should not make any difference right? Here http://www.outlookcode.com/codedetail.aspx?id=2092 is the full code of the routine. There are two areas that give me problems in BCM 2010 both are marked with the '--ERROR-- comments. Could someone help me to create the correct code for the two lines commented with --ERROR-- in this code? P.s. I have published this in the Code Essentials section, but maybe it should have been published in the Basic Outlook section istead. |
||
|
|
Rick Stroot
25-Aug-2010 13:16
I have still not managed to solve the problem above, can anyone have a look at my code and give me some hints on how to achieve what I try to do? |
||
|
|
Sue Mosher
26-Aug-2010 17:34
OK, I see better what you're doing. Thanks for the extra code. An On Error Resume Next statement should allow you to handle the case where case where the item doesn't exist: On Error Resume Next Set existContact = bcmContactsFldr.Items(strFullName) If existContact Is Nothing Then 'etc. The EntryID property cannot be used with Items.Find. Instead, use Namespace.GetItemFromID. |
||
|
|
Rick Stroot
27-Aug-2010 09:31
Thanks Sue, I have solved the first problem. However I am not an expert coder and do not understand how I would use the Namespace.GetItemFromID on the Accounts folder as there are three levels of hierarchy between the Accounts Folder (bcmRecordsFolder) and the Namespace (objNS) in my example (see lines below). Set objNS = olApp.GetNamespace("MAPI") Set olFolders = objNS.Session.Folders Set bcmRootFolder = olFolders("Business Contact Manager") Set bcmAccountsFldr = bcmRecordsFolder.Folders("Accounts") Would it be possible if you write me a couple of lines of code as an example on how to get the parent Account given a selected Business Contact? |
||
|
|
Sue Mosher
27-Aug-2010 09:39
The details of the folder hierarchy are irrelevant. Did you read the Help topic for Namespace.GetItemFromID? It explains that it takes as arguments, an EntryID value and an optional StoreID, which you need if the item you want is in a non-default store. Thus, building on the code you already have: Set objNS = olApp.GetNamespace("MAPI") Set olFolders = objNS.Folders ' get the BCM store and its StoreID Set bcmRootFolder = olFolders("Business Contact Manager") BCMStoreID = bcmRootFolder.StoreID ' get the EntryID stored in a custom property ParentID = existContact.UserProperties("Parent Entity EntryID") ' get the item corresponding to that EntryID Set myItem = objNS.GetItemFromID(ParentID, BCMStoreID) |
||
|
|
|||
