outlook move item

cah1982

Registered User.
Local time
Today, 08:26
Joined
May 7, 2005
Messages
27
Right I have the code in place but it will only work first time out look is opened, unless I have a msgbox on the first line and, I cant work out how to make it work with out it, obviously the msgbox isn't code doing any thing but it must be setting focus or some thing, here is the code, any help appreciated thanks

Dim strID As String
Dim olNS As Outlook.NameSpace
Dim olMail As Outlook.MailItem
Dim objAtt As Outlook.Attachment
Dim objDestFolder As Object

msgbox("test") < < < with this it works every time

Set objDestFolder = olMail.Parent.Folders("-=Site Surveys=-")

strID = MyMail.EntryID
Set olNS = Application.GetNamespace("MAPI")
Set olMail = olNS.GetItemFromID(strID)

olMail.Move objDestFolder
Set olNS = Nothing
Set olMail = Nothing
Set objDestFolder = Nothing
 
That isn't the actual code, is it? I don't see how, as you use olMail before setting it, and never set MyMail. I have a number of automated email import routines running, and all use:

outItem.Move (outTargetFolder)

without problems.
 
Hi Paul,

Here is the actual test code, the other was just a partial bit of a much larger one. It works on first email but none after that, but with the msgbox works everytime. Its run thought a run script on the mail rules

Sub RunMove(MyMail As Outlook.MailItem)
MsgBox ("start")
Dim strID As String
Dim olNS As Outlook.NameSpace
Dim olMail As Outlook.MailItem
Dim objAtt As Outlook.Attachment
Dim objDestFolder As Object

strID = MyMail.EntryID
Set olNS = Application.GetNamespace("MAPI")
Set olMail = olNS.GetItemFromID(strID)
Set objDestFolder = olMail.Parent.Folders("-=Site Surveys=-")


olMail.Subject = "Test Moves"
olMail.Save
olMail.Move objDestFolder

Set olNS = Nothing
Set olMail = Nothing
Set objAtt = Nothing
Set objDestFolder = Nothing

End Sub
 
ok ive kinda found the issue,

I also change the name of subject

With olMail
.Move objDestFolder
.Subject = "SS- Customer: " & Prefcus & " - " & Prefpd & " - Surveyed By: " & Prefby
.Save
End With

if the moves before it moves all emails, but wont change subject, if subject change is first it will only move first email, but again with the msg box at start of script it does them all
 

Users who are viewing this thread

Back
Top Bottom