Results 1 to 13 of 13

Thread: [RESOLVED] Cannot move emails

  1. #1

    Thread Starter
    Hyperactive Member tommygrayson's Avatar
    Join Date
    Aug 2005
    Location
    In my Nissan Silvia
    Posts
    433

    Resolved [RESOLVED] Cannot move emails

    Hi guys!!!



    Need help. Cannot move e-mail to folder. Don't know why.

    VB Code:
    1. Dim OrganizerApplication As New Outlook.Application
    2.     Dim OrganizerNS As Outlook.NameSpace
    3.     Dim OrganizerFolder As Outlook.Folders
    4.     Dim DestFolder As MAPIFolder
    5.     Dim InboxItem As Outlook.MailItem
    6.     Dim InboxCount As Integer
    7.     Dim DestFolderCount As Integer
    8.     Dim Sender As String
    9.     Dim CompareFolder As String
    10.     Set OrganizerNS = OrganizerApplication.GetNamespace("MAPI")
    11.     Set OrganizerFolder = OrganizerNS.Folders.Item("Mailbox - Ian Eco (DHL PH)").Folders
    12.     Set DestFolder = OrganizerNS.Folders.Item("IAN Personal")
    13.     InboxCount = 1
    14.     Do While Not InboxCount = OrganizerFolder.Item(2).Items.Count
    15.         On Error Resume Next
    16.         Set InboxItem = OrganizerFolder.Item(2).Items.Item(InboxCount)
    17.         If Err = 13 Then
    18.         Else
    19.             Sender = InboxItem.SenderEmailAddress
    20.             DestFolderCount = 1
    21.             Do While Not DestFolderCount = DestFolder.Folders.Count + 1
    22.                 CompareFolder = Replace(DestFolder.Folders.Item(DestFolderCount), " ", ".")
    23.                 If InStr(1, Sender, UCase(CompareFolder)) > 0 Then
    24.                     InboxItem.Move (DestFolder)
    25.                 End If
    26.                 DestFolderCount = DestFolderCount + 1
    27.             Loop
    28.         End If
    29.         Err = 0
    30.         InboxCount = InboxCount + 1
    31.     Loop

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Cannot move emails

    I take it that this is not your mailbox? Do you have the proper permissions when and if the other user shared or delegated his inbox?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Hyperactive Member tommygrayson's Avatar
    Join Date
    Aug 2005
    Location
    In my Nissan Silvia
    Posts
    433

    Re: Cannot move emails

    No this is my inbox in Exchange Server.

    But I wanted it to transfer to my Personal Folders.

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Cannot move emails

    "IAN Personal" is your added pst file?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Hyperactive Member tommygrayson's Avatar
    Join Date
    Aug 2005
    Location
    In my Nissan Silvia
    Posts
    433

    Re: Cannot move emails

    Yes it is.

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Cannot move emails

    Then you need to reference it by the StoreID also and not just the folder name possibly. Do you get a correct reference to it with the MAPIFolder object? Can you read items in it?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7

    Thread Starter
    Hyperactive Member tommygrayson's Avatar
    Join Date
    Aug 2005
    Location
    In my Nissan Silvia
    Posts
    433

    Re: Cannot move emails

    Yes I can read everything.

    I can also delete and copy the inbox mail message.

    I can also move it to the calendar which is very weird.

    I just can't move it to the Personal Folder.

    How do you use StoreID?

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Cannot move emails

    No, I mean can you read, add, delete and such on the pst mapifolder object?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9

    Thread Starter
    Hyperactive Member tommygrayson's Avatar
    Join Date
    Aug 2005
    Location
    In my Nissan Silvia
    Posts
    433

    Re: Cannot move emails

    Yes I can read, add, delete programmatically.

  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Cannot move emails

    Take out the "On Error Resume Next" and step through your code. What line is generating an error and what does it say?

    I dont know about this line:
    Set InboxItem = OrganizerFolder.Item(2).Items.Item(InboxCount)
    Shouldnt you beiterating through the items of the OrganizerFolder or is it a subfolder that your looking into?

    Also, dont like this loop:
    Do While Not InboxCount = OrganizerFolder.Item(2).Items.Count
    As you should either have a For x = 1 to OrganizerFolder.Item(2).Items.Count
    or a For Each itm In OrganizerFolder.Item(2).Items.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  11. #11

    Thread Starter
    Hyperactive Member tommygrayson's Avatar
    Join Date
    Aug 2005
    Location
    In my Nissan Silvia
    Posts
    433

    Re: Cannot move emails

    If I remove the On Error Resume Next I will get a Type Mismatch Error because I have a Meeting Request on my Inbox.

    The loop works but I will still change it for better code practice. Thanks for that.

    Yes you are right, I am trying to move my mails to their respective sub-folders.

    Here is the sample:

    Inbox
    Mail
    Personal Folder
    Folder for a
    Folder for b
    Folder for c

    Hope this gives you a clearer picture of what I mean.

  12. #12
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [RESOLVED] Cannot move emails

    Are these all top level pst files or folders or ? Can you draw teh folder structure or attact a small screen shot?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  13. #13

    Thread Starter
    Hyperactive Member tommygrayson's Avatar
    Join Date
    Aug 2005
    Location
    In my Nissan Silvia
    Posts
    433

    Re: [RESOLVED] Cannot move emails

    Quote Originally Posted by RobDog888
    Are these all top level pst files or folders or ? Can you draw teh folder structure or attact a small screen shot?
    Oh, thanks for your reply.

    I'm sorry if I did not told you that I found the error.

    I have forgotten that when you use the parenthesis in an expression it will definitely read as a function and not a sub procedure.

    VB Code:
    1. InboxItem.Move(Something)

    Will not work. It should be these:

    VB Code:
    1. InboxItem.Move Something

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width