This is to ensure that the INSERT statement doesnt fail when processing a folder thats named something like O Brian, with an embedded apostrophe. Again, I have a local table where the list items are saved for display on the demo form. Personally, Im very excited about this demo code because it brings together in one place all the snippets Ive used in various applications.
One could use a recordset object to add the record, which is how its handled in the next example, but I like to switch it up to keep things interesting. Address & ";" str Recip = str Recip & str Address & ";" Next With rst New . The code simply instantiates an Address List object and interrogates it for lists and items, inserting each one into the temp table as it goes. Its the kind of thing you could import into an application and start using right away and because it relies on late binding, you neednt worry about the version of Microsoft Outlook that the user has installed.
Since subfolders of subfolders are also enumerated, a function must be created that may be called recursively.
Hooking into an Outlook folder is relatively simple. One feature we implemented was an email lookup to our Customer Relationship Management database.
You basically need only two things: An instantiated Outlook object and a folder identifier. If the email address wasnt found to be in the database, the item was skipped.
Last month we discussed how to get data from Microsoft Access into Outlook objects, such as in the creation of new appointments, tasks, contacts and emails.
This month we perform the reverse operation: get data out of Outlook into Microsoft Access.
One final point: The code in the article has been modified to avoid line breaks where possible and will not exactly correspond to that found in the demo code.
I also noticed that some of my comment lines in the demo code were nonsense.The demo application includes the code for processing selected rows of the list box and its basic stuff, so I wont reproduce that here but the function it calls to process all emails for a named folder is shown below. Whats important to note here is that the variables l Folder and s Folder are passed to this function. For our top folders (Inbox and Sent Items) we need to pass the constants supplied by Outlook to the Get Default Folder method. This saved us from importing hundreds of spam and other emails that were not relative to our contacts database.Since this example uses late binding and no reference to the Outlook Library is set, I included comments clarifying that Inbox is 6 and Sent Items is 5. If you dont have a CRM list of emails you may wish to limit the import to persons who appear in your contact lists.The only other thing that might not be obvious is the int Dep variable. I found that some text parsing and cleanup had to be done to get a good list and once again, this extent cleanup may depend on the quality of your address lists. Get Namespace("MAPI") s SQL = "DELETE FROM tbl Contacts" Current Db. The code supplied with this article should be an adequate starting point for all your Outlook to Access automation projects.