How to copy an item to another folder using ItemAdd 
Author Message
 How to copy an item to another folder using ItemAdd

Hi,
I'm trying to monitor a folder for new contacts and when one is
created, make a copy of it in another folder. I can move it ok, but
when I try to copy, the program just loops and creates contacts like
crazy (it's like for every copy, it generates an ItemAdd again). Here
is my code, and I would be overly grateful if someone could give me
some help.

Private Sub olSourceItems_ItemAdd(ByVal Item As Object)

    Dim nms As Outlook.NameSpace
    Dim targetFld As Outlook.MAPIFolder
    Dim targetFolder As String

    targetFolder = "testdest"

    Set nms = Application.GetNamespace("MAPI")
    Set targetFld = nms.Folders("Personal
Folders").Folders(targetFolder)
    Item.Move targetFld (THIS WORKS FINE I just can't figure out how
to copy)

    Set targetFld = Nothing
    Set nms = Nothing

End Sub

Thank you for any help.



Tue, 19 Apr 2005 04:31:32 GMT  
 How to copy an item to another folder using ItemAdd
Try this:

Set objCopy = Item.Copy
objCopy.Move targetFld

--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
     Microsoft Outlook Programming: Jumpstart
     for Administrators, Power Users, and Developers
     http://www.slipstick.com/books/jumpstart.htm


Quote:
> Hi,
> I'm trying to monitor a folder for new contacts and when one is
> created, make a copy of it in another folder. I can move it ok, but
> when I try to copy, the program just loops and creates contacts like
> crazy (it's like for every copy, it generates an ItemAdd again). Here
> is my code, and I would be overly grateful if someone could give me
> some help.

> Private Sub olSourceItems_ItemAdd(ByVal Item As Object)

>     Dim nms As Outlook.NameSpace
>     Dim targetFld As Outlook.MAPIFolder
>     Dim targetFolder As String

>     targetFolder = "testdest"

>     Set nms = Application.GetNamespace("MAPI")
>     Set targetFld = nms.Folders("Personal
> Folders").Folders(targetFolder)
>     Item.Move targetFld (THIS WORKS FINE I just can't figure out how
> to copy)

>     Set targetFld = Nothing
>     Set nms = Nothing

> End Sub

> Thank you for any help.



Tue, 19 Apr 2005 06:35:43 GMT  
 How to copy an item to another folder using ItemAdd
Thanks so much, it worked!


Quote:
> Try this:

> Set objCopy = Item.Copy
> objCopy.Move targetFld

> --
> Sue Mosher, Outlook MVP
> Outlook and Exchange solutions at http://www.slipstick.com
> Author of
>      Microsoft Outlook Programming: Jumpstart
>      for Administrators, Power Users, and Developers
>      http://www.slipstick.com/books/jumpstart.htm



> > Hi,
> > I'm trying to monitor a folder for new contacts and when one is
> > created, make a copy of it in another folder. I can move it ok, but
> > when I try to copy, the program just loops and creates contacts like
> > crazy (it's like for every copy, it generates an ItemAdd again). Here
> > is my code, and I would be overly grateful if someone could give me
> > some help.

> > Private Sub olSourceItems_ItemAdd(ByVal Item As Object)

> >     Dim nms As Outlook.NameSpace
> >     Dim targetFld As Outlook.MAPIFolder
> >     Dim targetFolder As String

> >     targetFolder = "testdest"

> >     Set nms = Application.GetNamespace("MAPI")
> >     Set targetFld = nms.Folders("Personal
> > Folders").Folders(targetFolder)
> >     Item.Move targetFld (THIS WORKS FINE I just can't figure out how
> > to copy)

> >     Set targetFld = Nothing
> >     Set nms = Nothing

> > End Sub

> > Thank you for any help.



Tue, 19 Apr 2005 19:46:20 GMT  
 How to copy an item to another folder using ItemAdd
Hi,

See the way I am doing (towards the end of FOR... Next
loop). Hope you will understand the program code.

Sub selected()

Dim myuserproperty As UserProperty
Dim myOlApp As New Outlook.Application
Dim myOlExp As Outlook.Explorer
Dim myOlSel As Outlook.Selection
Dim mytaskitems As Items
Dim mytaskitem As TaskItem
Dim mymailitem As MailItem
Dim mycopiedmailitem As MailItem
Dim mymailitems As Items
Dim mycategory As String
Dim myresp As String
Dim myarea As String
Dim mytdate As Date
Dim myoption As Integer

Set myOlExp = myOlApp.ActiveExplorer
Set myOlSel = myOlExp.Selection
Set myNamespace = myOlApp.GetNamespace("MAPI")
Set myrootfolder = myNamespace.Folders("Personal folders")
Set myfolder = myrootfolder.Folders("Pending Tasks")

mytdate = Date

myoption = MsgBox("Do you want mention category / Owner",
vbYesNo)

If myoption = vbYes Then
    Taskinput.Show
    If cap = "Ok" Then
        mycategory = mycategory1
        myresp = myresp1
        myarea = myarea1
        mytdate = mytdate1
        Taskinput.Hide
    Else
        Taskinput.Hide
        Exit Sub
    End If
End If
For x = 1 To myOlSel.Count
    Set mymailitem = myOlSel.Item(x)
    Set mytaskitem = Application.CreateItem(olTaskItem)
    mytaskitem.Subject = mymailitem.Subject
    mytaskitem.Categories = mycategory
    mytaskitem.BillingInformation = myarea
    mytaskitem.StartDate = mymailitem.ReceivedTime
    mytaskitem.DueDate = mytdate
    mytaskitem.Body = mymailitem.SenderName
    mytaskitem.Role = myresp
    mytaskitem.ReminderTime = mytdate
    mytaskitem.ReminderOverrideDefault = True
    mytaskitem.ReminderSet = True

    Set mycopiedmailitem = mymailitem.Copy
    mycopiedmailitem.Move myfolder
    mymailitem.Delete
    mytaskitem.Close (olSave)
Next x
End Sub

Quote:
>-----Original Message-----
>Hi,
>I'm trying to monitor a folder for new contacts and when
one is
>created, make a copy of it in another folder. I can move
it ok, but
>when I try to copy, the program just loops and creates
contacts like
>crazy (it's like for every copy, it generates an ItemAdd
again). Here
>is my code, and I would be overly grateful if someone
could give me
>some help.

>Private Sub olSourceItems_ItemAdd(ByVal Item As Object)

>    Dim nms As Outlook.NameSpace
>    Dim targetFld As Outlook.MAPIFolder
>    Dim targetFolder As String

>    targetFolder = "testdest"

>    Set nms = Application.GetNamespace("MAPI")
>    Set targetFld = nms.Folders("Personal
>Folders").Folders(targetFolder)
>    Item.Move targetFld (THIS WORKS FINE I just can't
figure out how
>to copy)

>    Set targetFld = Nothing
>    Set nms = Nothing

>End Sub

>Thank you for any help.
>.



Wed, 20 Apr 2005 02:28:02 GMT  
 How to copy an item to another folder using ItemAdd
I'm missing something here. I can't see what this routine has to do with
monitoring a folder with ItemAdd.

--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
     Microsoft Outlook Programming: Jumpstart
     for Administrators, Power Users, and Developers
     http://www.slipstick.com/books/jumpstart.htm


Quote:
> Hi,

> See the way I am doing (towards the end of FOR... Next
> loop). Hope you will understand the program code.

> Sub selected()

> Dim myuserproperty As UserProperty
> Dim myOlApp As New Outlook.Application
> Dim myOlExp As Outlook.Explorer
> Dim myOlSel As Outlook.Selection
> Dim mytaskitems As Items
> Dim mytaskitem As TaskItem
> Dim mymailitem As MailItem
> Dim mycopiedmailitem As MailItem
> Dim mymailitems As Items
> Dim mycategory As String
> Dim myresp As String
> Dim myarea As String
> Dim mytdate As Date
> Dim myoption As Integer

> Set myOlExp = myOlApp.ActiveExplorer
> Set myOlSel = myOlExp.Selection
> Set myNamespace = myOlApp.GetNamespace("MAPI")
> Set myrootfolder = myNamespace.Folders("Personal folders")
> Set myfolder = myrootfolder.Folders("Pending Tasks")

> mytdate = Date

> myoption = MsgBox("Do you want mention category / Owner",
> vbYesNo)

> If myoption = vbYes Then
>     Taskinput.Show
>     If cap = "Ok" Then
>         mycategory = mycategory1
>         myresp = myresp1
>         myarea = myarea1
>         mytdate = mytdate1
>         Taskinput.Hide
>     Else
>         Taskinput.Hide
>         Exit Sub
>     End If
> End If
> For x = 1 To myOlSel.Count
>     Set mymailitem = myOlSel.Item(x)
>     Set mytaskitem = Application.CreateItem(olTaskItem)
>     mytaskitem.Subject = mymailitem.Subject
>     mytaskitem.Categories = mycategory
>     mytaskitem.BillingInformation = myarea
>     mytaskitem.StartDate = mymailitem.ReceivedTime
>     mytaskitem.DueDate = mytdate
>     mytaskitem.Body = mymailitem.SenderName
>     mytaskitem.Role = myresp
>     mytaskitem.ReminderTime = mytdate
>     mytaskitem.ReminderOverrideDefault = True
>     mytaskitem.ReminderSet = True

>     Set mycopiedmailitem = mymailitem.Copy
>     mycopiedmailitem.Move myfolder
>     mymailitem.Delete
>     mytaskitem.Close (olSave)
> Next x
> End Sub

> >-----Original Message-----
> >Hi,
> >I'm trying to monitor a folder for new contacts and when
> one is
> >created, make a copy of it in another folder. I can move
> it ok, but
> >when I try to copy, the program just loops and creates
> contacts like
> >crazy (it's like for every copy, it generates an ItemAdd
> again). Here
> >is my code, and I would be overly grateful if someone
> could give me
> >some help.

> >Private Sub olSourceItems_ItemAdd(ByVal Item As Object)

> >    Dim nms As Outlook.NameSpace
> >    Dim targetFld As Outlook.MAPIFolder
> >    Dim targetFolder As String

> >    targetFolder = "testdest"

> >    Set nms = Application.GetNamespace("MAPI")
> >    Set targetFld = nms.Folders("Personal
> >Folders").Folders(targetFolder)
> >    Item.Move targetFld (THIS WORKS FINE I just can't
> figure out how
> >to copy)

> >    Set targetFld = Nothing
> >    Set nms = Nothing

> >End Sub

> >Thank you for any help.
> >.



Wed, 20 Apr 2005 04:20:35 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Howto trap MAPIFolder.Items.ItemAdd on Sent Items Folder

2. Copying Items in the ItemAdd() Event?

3. ItemAdd on a Folder that a Rule uses

4. using ItemAdd on many folders to find new mail

5. Copy a file in a folder and past the copy in another folder

6. Copy Item (contact) to another folder

7. How to copy an item from Draft folder to Outbox

8. Help Copy Public Folder Calander Items to Personal Calendar(code sample)

9. protecting a public folder from copying an item

10. Extra copy of moved mailitem appears in Deleted Items folder

11. Copy viewed items from one folder into email body

12. Copy Outlook2000 Mail item to another folder.

 

 
Powered by phpBB® Forum Software