How to login as different user?

J

John Riddle

Hello,

I've got a folder with items that my users do not have permission to delete
items from. The thing is that I have a macro that runs in the VBA project that
does need to delete items from this folder. How can I do this? I tried using
CDO to logon as a different user created with permission to delete items from
this folder and VBA still uses the normal user and gives a "permission denied
error".

Here's my code:

Sub TestMAPIDelete()
Dim objSession As MAPI.Session
Dim objMessage As MAPI.Message
Dim OLMessages As MAPIFolder
Dim OLMessage As ContactItem

Set OLMessages = Application.Session.Folders("Public Folders").Folders("All
Public Folders").Folders("Candidates")
strStoreID = OLMessages.StoreID

Set OLMessage = OLMessages.Items.Item("Test Delete")
strMessageID = OLMessage.EntryID

Set objSession = CreateObject("MAPI.Session")
objSession.Logon "Deleter", "JRiddle#1", False, False, 0

Set objMessage = objSession.GetMessage(strMessageID, strStoreID)

objMessage.Delete

objSession.Logoff

Set objMessage = Nothing
Set objMessages = Nothing
Set OLMessages = Nothing
Set OLMessage = Nothing
Set objSession = Nothing

End Sub

What am I doing wrong? Do I need a whole new approach? Is this possible, what
I need to do?

Thanks,

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top