Help with 'A Program is trying to access'

S

stevebuy

Would really appreciate help on this one.

Previously accessing MailItem.SenderName or MailItem.To using
objNS.GetDefaultFolder(olFolderInbox).Items was fine.

Now I simply want to do the same item access using
ActiveExplorer.Selection and I keep getting the annoying error "A
Program is trying to access email addresses".

All I want to do is to record the sender whenever an email is selected
and a button is pressed.

Since ActiveExplorer.Selection seems to trigger that annoying message,
is there a better way of doing it.

Many many thanks in advance for any help on the matter.

SteveB.
 
S

Sue Mosher [MVP-Outlook]

If you're using Outlook 2003, you shouldn't get a prompt. Please post a snippet that shows how you're instantiating ActiveExplorer and its parent Application.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
S

stevebuy

Really appreciate ye replying :
The code is I'm using is taken from your Jumpstart book. I'm using
Office 2003 SP1.

Private Sub btnCustomReceived_Click(ByVal Ctrl As
Office.CommandBarButton, CancelDefault As Boolean)
On Error Resume Next

Dim objApp As Outlook.Application
Dim objSelection As Outlook.Selection

Set objApp = CreateObject("Outlook.Application")
Set objSelection = objApp.ActiveExplorer.Selection
Set myItem = objSelection.Item(1)


If I then reference any of myItem.To, myItem.SenderName, myItem.Body,
the message is triggered.
 
S

Sue Mosher [MVP-Outlook]

In Outlook 2003 VBA, to avoid security prompts, you need to derive all objects from the intrinsic Application object that Outlook VBA supports. Use it instead of instantiating a new Outlook.Application object. You can just replace

Set objApp = CreateObject("Outlook.Application")

with

Set objApp = Application

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
S

stevebuy

Thank a million for the help, I dont know how many more hours it would
have take to figure it out.
The "Set objApp = Application" solution worked!

In the last hour I used the RunAScriptRuleRoutine workaround as linked
above, also with success.

Again, much appreciated.

SteveB.
 
Top