Expert One-on-One Microsoft Access Application Development

As a response to Outlook’s vulnerability to various email viruses, Microsoft added some security features to Outlook 2000 (optional for that version, built in to later versions) that unfortunately made life much more difficult for Office users, especially those who write VBA code to work with Outlook objects. If you have Office XP or 2003, Outlook 2000 with the Outlook security patch, or Office 2000 with Service Pack 2, you will see the pop-up shown in Figure 12.20 whenever your Access code works with Outlook objects, if the code works with mail messages, address books, and contacts.

Figure 12.20

This pop-up is the Object Model Guardian. While Microsoft’s intention with this irritating “feature” was to protect Outlook objects from modification by hackers, in real life the Object Model Guardian mostly appears as an annoying interruption in the smooth running of Office VBA code. Instead of your code running automatically, somebody has to hover over the computer, responding to pop-ups, giving access for a few minutes at a time (10 minutes is the top choice, which may not be enough for lengthy merges). Running a long merge over lunch is out of the question, because if no one responds to the dialog, the merge stops dead.

Since the introduction of the Outlook 2000 security patch, the only way to avoid this annoying pop-up has been to avoid upgrading to Office XP or 2003, stay in Outlook 2000, and not install the security patch that implements this feature. However, this is no longer the case—Dmitry Streblechenko developed the Redemption Library for Outlook, which lets your VBA code run unaffected by the security patch, and also adds a number of extra features that are very useful for working with Outlook objects in code.

The Redemption Libary for Outlook can be downloaded from www.dimastr.com. Two versions are available: a free version for noncommercial use and a distributable version with extra features for $199.99. The distributable version is required for commercial use of the Redemption Library.

To use the Redemption library in your code, you need to download and install it and set a reference to the SafeOutlook Library in the References dialog. I recommend placing the Redemption.dll file in the AddIns folder (typically C:\Documents and Settings\Administrator\Application Data\Microsoft\_AddIns for a standalone Office installation in Windows 2000, or C:\Windows\Application Data\_Microsoft\Addins for Windows ME). Placing this file in the Addins folder will make it easy to install as an add-in in Access.

To set the reference, open any Access 2000 or higher database, open a module, and select References from the Tools menu. If you placed Redemption.dll in the Addins folder, scroll down until you can see the SafeOutlook Library selection, and check it, as shown in Figure 12.21.

If you have downloaded and installed the Redemption library, you can test working with Outlook without the annoying Object Model Guardian pop-ups, using the Outlook Data Exchange with Redemption database, which has a reference set to the SafeOutlook library and some necessary modifications to code on some of the procedures that work with mail messages and contacts.

Figure 12.21

First, you need to declare two sets of contact and mail message variables, both as Object.

‘Must declare Redemption objects and corresponding Outlook objects as Object Private ocon As Object Private con As Object Private omsg As Object Private msg As Object

Then, whenever your code works with a contact or mail message, replace the original line setting the ContactItem (con) or MailItem (msg) variable with a set of lines like the following:

‘Set the standard and Safe ContactItem variables Set ocon = ins.CurrentItem Set con = New Redemption.SafeContactItem con.Item = ocon

From this point on, you can use the con (or msg) variable as usual, and you will not see the annoying Object Model Guardian when the code runs.

Категории