dbTalk Databases Forums  

Access VBA to Move Outlook Item

comp.databases.ms-access comp.databases.ms-access


Discuss Access VBA to Move Outlook Item in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Boyd
 
Posts: n/a

Default Access VBA to Move Outlook Item - 06-09-2011 , 10:20 AM






I have the following VBA code (behind an Access button) that moves all
emails from one Outlook folder to another. The code works fine for
users of Office 2007, but not with Office 2010. I'm receiving an
"Operation Failed" error on "fld.Items(1).Move fld2". Any thoughts?

Dim appOutlook As Outlook.Application
Dim nms As Outlook.nameSpace
Dim fld As Outlook.MAPIFolder
Dim fld2 As Outlook.MAPIFolder

Set appOutlook = GetObject(, "Outlook.Application")
Set nms = appOutlook.GetNamespace("MAPI")
Set fld = nms.PickFolder

While fld.Items.Count > 0
Set fld2 = fld.Folders("Emails Processed")
fld.Items(1).Move fld2
Wend

Reply With Quote
  #2  
Old   
Phil
 
Posts: n/a

Default Re: Access VBA to Move Outlook Item - 06-10-2011 , 03:02 AM






On 09/06/2011 16:20:03, Boyd wrote:
Quote:
I have the following VBA code (behind an Access button) that moves all
emails from one Outlook folder to another. The code works fine for
users of Office 2007, but not with Office 2010. I'm receiving an
"Operation Failed" error on "fld.Items(1).Move fld2". Any thoughts?

Dim appOutlook As Outlook.Application
Dim nms As Outlook.nameSpace
Dim fld As Outlook.MAPIFolder
Dim fld2 As Outlook.MAPIFolder

Set appOutlook = GetObject(, "Outlook.Application")
Set nms = appOutlook.GetNamespace("MAPI")
Set fld = nms.PickFolder

While fld.Items.Count > 0
Set fld2 = fld.Folders("Emails Processed")
fld.Items(1).Move fld2
Wend

Try, but remove all the bits about a progress meter. (I can't stand the
horrible little thing that Office 2010 use, so I created my own progress
meter)

Function ZZCopyContacts(FromFolder As String, ToFolder As String)
' ?CopyContacts("Test", "Temporary")

Dim OlApp As Outlook.Application
Dim OlNS As Outlook.NameSpace
Dim MyFolder As MAPIFolder
Dim OlFromFolder As MAPIFolder
Dim OlToFolder As MAPIFolder
Dim OlItems As Items
Dim CopiedItem As Object
Dim i As Integer

' Fields for Progress Meter
Dim PMFrmMax As Long
Dim RecordNo As Long
Dim Smoothness As Integer

On Error GoTo CopyContacts_Err

Set OlApp = CreateObject("Outlook.Application")
Set OlNS = OlApp.GetNamespace("MAPI")
Set MyFolder = OlNS.GetDefaultFolder(olFolderContacts)

If MyFolder.Name = ToFolder Then
Set OlToFolder = OlNS.GetDefaultFolder(olFolderContacts)
Else
Set OlToFolder = MyFolder.Folders(ToFolder)
End If

If MyFolder.Name = FromFolder Then
Set OlFromFolder = OlNS.GetDefaultFolder(olFolderContacts)
Else
Set OlFromFolder = MyFolder.Folders(FromFolder)
End If

' Set maxima etc
PMFrmMax = CLng(OlFromFolder.Items.Count)
Smoothness = Int(PMFrmMax \ 200)
If Nz(Smoothness) < 1 Then
Smoothness = 1
End If

' Set default caption, label & colour
' If titles are blank, default ones are loaded
' if colours are negative, default red and green are loaded
PMeterRainbow.RainShowProgress
PMeterRainbow.RainSetCaption tion = "Outlook" ' Progress Meter Caption
PMeterRainbow.RainSetTitle itle = "Copying contacts from " & FromFolder & "
to " & ToFolder PMeterRainbow.RainSetLabToProcess = "" ' Progress Meter label
Caption PMeterRainbow.RainSetLabProcessed = "" ' Progress Meter label
Caption' Progress Meter PMeterRainbow.RainSetFromColour = -1 ' Default from
colour PMeterRainbow.RainSetToColour = -1 ' Default to colour
PMeterRainbow.RainSetToProcess = PMFrmMax ' RecordCount
PMeterRainbow.RainSetSmoothness = Smoothness

For i = 1 To OlFromFolder.Items.Count
Set OlItems = OlFromFolder.Items
Set CopiedItem = OlItems.Item(i).Copy
CopiedItem.Move OlToFolder
RecordNo = RecordNo + 1
If RecordNo Mod Smoothness = 0 Then
PMeterRainbow.RainIncOne (RecordNo)
End If
Next i

PMeterRainbow.RainHideProgress
Exit Function

CopyContacts_Err:
If ZZIsLoaded("ProgressMeterRainbow") Then
PMeterRainbow.RainHideProgress
End If
Stop

End Function

Reply With Quote
  #3  
Old   
Boyd
 
Posts: n/a

Default Re: Access VBA to Move Outlook Item - 06-14-2011 , 09:52 AM



This doesn't fix it .. still receiving "The operation failed" error
message with the "CopiedItem.Move OlToFolder" code.
What specifically would be different between Access/Outlook 2007 and
2010 that would now prevent an item from being moved to another folder
thru code? Is this a security issue? Any thoughts?

Reply With Quote
  #4  
Old   
Phil
 
Posts: n/a

Default Re: Access VBA to Move Outlook Item - 06-14-2011 , 11:12 AM



On 14/06/2011 15:52:16, Boyd wrote:
Quote:
This doesn't fix it .. still receiving "The operation failed" error
message with the "CopiedItem.Move OlToFolder" code.
What specifically would be different between Access/Outlook 2007 and
2010 that would now prevent an item from being moved to another folder
thru code? Is this a security issue? Any thoughts?

Sorry, nothing more to say. Routine works for me in both AK2 and access 2010.

Phil

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.