Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming VBA / September 2005

Tip: Looking for answers? Try searching our database.

move task items to different account

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
vonclausowitz@gmail.com - 28 Sep 2005 20:03 GMT
Hi All,

I have found some code to move Outlook items around.
It uses the GetFolderFromID function.

I can get the source and the destination folder but I can't move the
task items to another folder.
I want to move tasks from my the general email account INFO to a
subfolder Old Tasks in the general account INFO. My own email account
is called INFO4.

This is de code I have, anyone what's wrong with it?

Private objNS As Object                           'Outlook.NameSpace
Private strSrcEntryId As String
Private strSrcStoreId As String
Private strDstEntryId As String
Private strDstStoreId As String

Private Sub btnGo_Click()

   Dim item As Object                             'Outlook.MailItem
   Dim olSrcFolder As Outlook.MAPIFolder
   Dim ReadItems As Items

   On Error GoTo btnGo_Click_Error

   Set olSrcFolder = objNS.GetFolderFromID(strSrcEntryId,
strSrcStoreId)
   Set ReadItems = olSrcFolder.Items
   Set item = ReadItems.Find("[Unread] = false")

   Do While Not (item Is Nothing)

       item.Move objNS.GetFolderFromID(strDstEntryId, strDstStoreId)
       Set item = ReadItems.FindNext

   Loop

   Set item = Nothing
   Set ReadItems = Nothing
   Set olSrcFolder = Nothing

   On Error GoTo 0
   Exit Sub

btnGo_Click_Error:

   MsgBox "Error " & Err.Number & " (" & Err.Description & ") in
procedure btnGo_Click of MoveEmailsAround"

End Sub

Private Sub btnSrcFolderBrowse_Click()
   On Error Resume Next

   Dim olFolder As Outlook.MAPIFolder
   Set olFolder = objNS.PickFolder
   If Not IsNull(olFolder) Then
       txtSrcFolder.Text = olFolder.Name
       strSrcEntryId = olFolder.EntryID
       strSrcStoreId = olFolder.StoreID
   End If
   Set olFolder = Nothing

End Sub

Private Sub btnDstFolderBrowse_Click()
   On Error Resume Next

   Dim olFolder As Outlook.MAPIFolder
   Set olFolder = objNS.PickFolder
   If Not IsNull(olFolder) Then
       txtDstFolder.Text = olFolder.Name
       strDstEntryId = olFolder.EntryID
       strDstStoreId = olFolder.StoreID
   End If
   Set olFolder = Nothing
End Sub

Private Sub Form_Load()
   'Set objApp = CreateObject("Outlook.application")
   Set objNS = Outlook.Application.GetNamespace("MAPI")
End Sub

Private Sub Form_Unload(Cancel As Integer)
   'Set objApp = Nothing
   Set objNS = Nothing
End Sub

Regards
Marco
The Netherlands
Michael Bauer - 29 Sep 2005 04:33 GMT
Am 28 Sep 2005 12:03:43 -0700 schrieb vonclausowitz@gmail.com:

Marco, please try the Restrict method instead of Find. Then use a For
Next backwards instead of the Do While.

BTW: IsNull works for Variants only. For objects you need to use this:

If not olFolder is nothing then ...

Signature

Viele Gruesse / Best regards
Michael Bauer - MVP Outlook

> Hi All,
>
[quoted text clipped - 89 lines]
> Marco
> The Netherlands
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.