A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Move MailItems to another folder



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old June 23rd 07, 03:28 PM posted to microsoft.public.outlook.program_vba
Gvaram
external usenet poster
 
Posts: 14
Default Move MailItems to another folder

I want to move MailItems from one folder to another. I know EntryID's of
those mails I want to move and I wrote simple code to do it. But, when
executing Item.Move, error occures - "An unsent message can not be flaged
complete."

Sub aaaaaaaaaaaaaaa()
Dim ns As NameSpace
Dim Archive_0612 As MAPIFolder
Dim FromFolder As MAPIFolder
Dim Item As MailItem
Dim t As Long
Dim DBS As New ADODB.Connection
Dim rst As New ADODB.Recordset

Set ns = GetNamespace("MAPI")
Set FromFolder= ns.Folders.Item("Posloan.Risk")
Set FromFolder= FromFolder.Folders.Item("Inbox")
Set Archive_0612 = ns.Folders.Item("Archive Folders")
Set Archive_0612 = Archive_0612.Folders.Item("Inbox")

With DBS
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0"
.Open "D:\MailID.mdb"
End With
rst.Open "SELECT MailIDs.* FROM MailIDs ORDER BY MailIDs.EntryTime;", DBS,
adOpenKeyset, adLockPessimistic
rst.MoveFirst
For t = 0 To rst.RecordCount - 1
Set Item = ns.GetItemFromID(rst!EntryID, FromFolder.StoreID)
Item.Move Archive_0612 'HERE IS THE PROBLEM......
rst!Done = 1
rst.MoveNext
Next t

rst.Close
DBS.Close

End Sub

Please, someone help me with this...
Ads
  #2  
Old June 24th 07, 08:31 AM posted to microsoft.public.outlook.program_vba
Michael Bauer [MVP - Outlook]
external usenet poster
 
Posts: 1,885
Default Move MailItems to another folder



Before moving the item check if it's flagged as completed; if so, delete the
flag, move the item and set the flag again.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Organize Outlook email:
http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6

Am Sat, 23 Jun 2007 06:28:02 -0700 schrieb Gvaram:

I want to move MailItems from one folder to another. I know EntryID's of
those mails I want to move and I wrote simple code to do it. But, when
executing Item.Move, error occures - "An unsent message can not be flaged
complete."

Sub aaaaaaaaaaaaaaa()
Dim ns As NameSpace
Dim Archive_0612 As MAPIFolder
Dim FromFolder As MAPIFolder
Dim Item As MailItem
Dim t As Long
Dim DBS As New ADODB.Connection
Dim rst As New ADODB.Recordset

Set ns = GetNamespace("MAPI")
Set FromFolder= ns.Folders.Item("Posloan.Risk")
Set FromFolder= FromFolder.Folders.Item("Inbox")
Set Archive_0612 = ns.Folders.Item("Archive Folders")
Set Archive_0612 = Archive_0612.Folders.Item("Inbox")

With DBS
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0"
.Open "D:\MailID.mdb"
End With
rst.Open "SELECT MailIDs.* FROM MailIDs ORDER BY MailIDs.EntryTime;", DBS,
adOpenKeyset, adLockPessimistic
rst.MoveFirst
For t = 0 To rst.RecordCount - 1
Set Item = ns.GetItemFromID(rst!EntryID, FromFolder.StoreID)
Item.Move Archive_0612 'HERE IS THE PROBLEM......
rst!Done = 1
rst.MoveNext
Next t

rst.Close
DBS.Close

End Sub

Please, someone help me with this...

  #3  
Old June 24th 07, 06:55 PM posted to microsoft.public.outlook.program_vba
Gvaram
external usenet poster
 
Posts: 14
Default Move MailItems to another folder

Thank you very much. I did it and it works now
But another question. after moving item I wrote "Item.FlagStatus =
olFlagComplete", but it does not change anithing. What should I do to mark
the items as completed?


"Michael Bauer [MVP - Outlook]" wrote:



Before moving the item check if it's flagged as completed; if so, delete the
flag, move the item and set the flag again.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Organize Outlook email:
http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6

Am Sat, 23 Jun 2007 06:28:02 -0700 schrieb Gvaram:

I want to move MailItems from one folder to another. I know EntryID's of
those mails I want to move and I wrote simple code to do it. But, when
executing Item.Move, error occures - "An unsent message can not be flaged
complete."

Sub aaaaaaaaaaaaaaa()
Dim ns As NameSpace
Dim Archive_0612 As MAPIFolder
Dim FromFolder As MAPIFolder
Dim Item As MailItem
Dim t As Long
Dim DBS As New ADODB.Connection
Dim rst As New ADODB.Recordset

Set ns = GetNamespace("MAPI")
Set FromFolder= ns.Folders.Item("Posloan.Risk")
Set FromFolder= FromFolder.Folders.Item("Inbox")
Set Archive_0612 = ns.Folders.Item("Archive Folders")
Set Archive_0612 = Archive_0612.Folders.Item("Inbox")

With DBS
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0"
.Open "D:\MailID.mdb"
End With
rst.Open "SELECT MailIDs.* FROM MailIDs ORDER BY MailIDs.EntryTime;", DBS,
adOpenKeyset, adLockPessimistic
rst.MoveFirst
For t = 0 To rst.RecordCount - 1
Set Item = ns.GetItemFromID(rst!EntryID, FromFolder.StoreID)
Item.Move Archive_0612 'HERE IS THE PROBLEM......
rst!Done = 1
rst.MoveNext
Next t

rst.Close
DBS.Close

End Sub

Please, someone help me with this...


  #4  
Old June 25th 07, 12:34 AM posted to microsoft.public.outlook.program_vba
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default Move MailItems to another folder

Move() returns the new item, the original item must be immediatley
dereferenced:

set Item = Item.Move(Archive_0612)

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"Gvaram" wrote in message
...
Thank you very much. I did it and it works now
But another question. after moving item I wrote "Item.FlagStatus =
olFlagComplete", but it does not change anithing. What should I do to mark
the items as completed?


"Michael Bauer [MVP - Outlook]" wrote:



Before moving the item check if it's flagged as completed; if so, delete
the
flag, move the item and set the flag again.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Organize Outlook email:

http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6

Am Sat, 23 Jun 2007 06:28:02 -0700 schrieb Gvaram:

I want to move MailItems from one folder to another. I know EntryID's
of
those mails I want to move and I wrote simple code to do it. But, when
executing Item.Move, error occures - "An unsent message can not be
flaged
complete."

Sub aaaaaaaaaaaaaaa()
Dim ns As NameSpace
Dim Archive_0612 As MAPIFolder
Dim FromFolder As MAPIFolder
Dim Item As MailItem
Dim t As Long
Dim DBS As New ADODB.Connection
Dim rst As New ADODB.Recordset

Set ns = GetNamespace("MAPI")
Set FromFolder= ns.Folders.Item("Posloan.Risk")
Set FromFolder= FromFolder.Folders.Item("Inbox")
Set Archive_0612 = ns.Folders.Item("Archive Folders")
Set Archive_0612 = Archive_0612.Folders.Item("Inbox")

With DBS
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0"
.Open "D:\MailID.mdb"
End With
rst.Open "SELECT MailIDs.* FROM MailIDs ORDER BY MailIDs.EntryTime;",
DBS,
adOpenKeyset, adLockPessimistic
rst.MoveFirst
For t = 0 To rst.RecordCount - 1
Set Item = ns.GetItemFromID(rst!EntryID, FromFolder.StoreID)
Item.Move Archive_0612 'HERE IS THE PROBLEM......
rst!Done = 1
rst.MoveNext
Next t

rst.Close
DBS.Close

End Sub

Please, someone help me with this...




  #5  
Old June 25th 07, 06:38 AM posted to microsoft.public.outlook.program_vba
Michael Bauer [MVP - Outlook]
external usenet poster
 
Posts: 1,885
Default Move MailItems to another folder



Additionally to Dmitry, the after changing the item it must be saved.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Organize Outlook email:
http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6

Am Sun, 24 Jun 2007 09:55:01 -0700 schrieb Gvaram:

Thank you very much. I did it and it works now
But another question. after moving item I wrote "Item.FlagStatus =
olFlagComplete", but it does not change anithing. What should I do to mark
the items as completed?


"Michael Bauer [MVP - Outlook]" wrote:



Before moving the item check if it's flagged as completed; if so, delete

the
flag, move the item and set the flag again.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Organize Outlook email:

http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6

Am Sat, 23 Jun 2007 06:28:02 -0700 schrieb Gvaram:

I want to move MailItems from one folder to another. I know EntryID's of
those mails I want to move and I wrote simple code to do it. But, when
executing Item.Move, error occures - "An unsent message can not be

flaged
complete."

Sub aaaaaaaaaaaaaaa()
Dim ns As NameSpace
Dim Archive_0612 As MAPIFolder
Dim FromFolder As MAPIFolder
Dim Item As MailItem
Dim t As Long
Dim DBS As New ADODB.Connection
Dim rst As New ADODB.Recordset

Set ns = GetNamespace("MAPI")
Set FromFolder= ns.Folders.Item("Posloan.Risk")
Set FromFolder= FromFolder.Folders.Item("Inbox")
Set Archive_0612 = ns.Folders.Item("Archive Folders")
Set Archive_0612 = Archive_0612.Folders.Item("Inbox")

With DBS
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0"
.Open "D:\MailID.mdb"
End With
rst.Open "SELECT MailIDs.* FROM MailIDs ORDER BY MailIDs.EntryTime;",

DBS,
adOpenKeyset, adLockPessimistic
rst.MoveFirst
For t = 0 To rst.RecordCount - 1
Set Item = ns.GetItemFromID(rst!EntryID, FromFolder.StoreID)
Item.Move Archive_0612 'HERE IS THE PROBLEM......
rst!Done = 1
rst.MoveNext
Next t

rst.Close
DBS.Close

End Sub

Please, someone help me with this...


  #6  
Old June 25th 07, 01:46 PM posted to microsoft.public.outlook.program_vba
Gvaram
external usenet poster
 
Posts: 14
Default Move MailItems to another folder

Fine...
Thank you both

"Michael Bauer [MVP - Outlook]" wrote:



Additionally to Dmitry, the after changing the item it must be saved.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Organize Outlook email:
http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6

Am Sun, 24 Jun 2007 09:55:01 -0700 schrieb Gvaram:

Thank you very much. I did it and it works now
But another question. after moving item I wrote "Item.FlagStatus =
olFlagComplete", but it does not change anithing. What should I do to mark
the items as completed?


"Michael Bauer [MVP - Outlook]" wrote:



Before moving the item check if it's flagged as completed; if so, delete

the
flag, move the item and set the flag again.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Organize Outlook email:

http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6

Am Sat, 23 Jun 2007 06:28:02 -0700 schrieb Gvaram:

I want to move MailItems from one folder to another. I know EntryID's of
those mails I want to move and I wrote simple code to do it. But, when
executing Item.Move, error occures - "An unsent message can not be

flaged
complete."

Sub aaaaaaaaaaaaaaa()
Dim ns As NameSpace
Dim Archive_0612 As MAPIFolder
Dim FromFolder As MAPIFolder
Dim Item As MailItem
Dim t As Long
Dim DBS As New ADODB.Connection
Dim rst As New ADODB.Recordset

Set ns = GetNamespace("MAPI")
Set FromFolder= ns.Folders.Item("Posloan.Risk")
Set FromFolder= FromFolder.Folders.Item("Inbox")
Set Archive_0612 = ns.Folders.Item("Archive Folders")
Set Archive_0612 = Archive_0612.Folders.Item("Inbox")

With DBS
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0"
.Open "D:\MailID.mdb"
End With
rst.Open "SELECT MailIDs.* FROM MailIDs ORDER BY MailIDs.EntryTime;",

DBS,
adOpenKeyset, adLockPessimistic
rst.MoveFirst
For t = 0 To rst.RecordCount - 1
Set Item = ns.GetItemFromID(rst!EntryID, FromFolder.StoreID)
Item.Move Archive_0612 'HERE IS THE PROBLEM......
rst!Done = 1
rst.MoveNext
Next t

rst.Close
DBS.Close

End Sub

Please, someone help me with this...


 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Hot to speed up MailItems access Ivan Add-ins for Outlook 8 June 27th 07 06:39 PM
automatically move item from one folder to another folder Venkat Outlook and VBA 1 January 22nd 07 05:01 PM
move to folder rule sends to wrong folder Holden Outlook - General Queries 0 December 10th 06 07:18 AM
Copy mail item to one folder and then move it to another folder LDMueller Outlook - Using Forms 1 September 15th 06 04:15 PM
After I've moved a note from Inbox to folder A, I can't move it to Folder B. [email protected] Outlook - General Queries 0 August 9th 06 11:46 PM


All times are GMT +1. The time now is 08:39 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.