V
vonclausowitz
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
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