Results 1 to 3 of 3
  1. #1
    TOPSie is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Mar 2021
    Posts
    108

    What is different?

    My main PC has developed a few issues, so I have gone back to an older PC. Both are Windows10 with Office 2016. I have copied a complete Access application and for the most part it is functioning correctly.
    Except for a routine which reads Emails from a sub folder of my Inbox.
    Code:
    Set OutlookApp = CreateObject("Outlook.Application")
    Set OutlookNamespace = OutlookApp.GetNamespace("MAPI")
    MsgBox OutlookNamespace.CurrentUser
    Set Folder = OutlookNamespace.GetDefaultFolder(olFolderInbox)
    
    Set TOPSFolder = Folder.Folders("TOPS")
    TOPSFolder.Items.Sort "[ReceivedTime]", True
    
    i = 1
    
    For Each OutlookMail In TOPSFolder.Items
    On my original PC this worked correctly. But on my older PC the For loop exits immediately as it cannot find any mail in the folder but also gives no error (but viewed in Outlook there are at least 40 emails)


    As the two systems should be identical I cannot see where to look for the answer.
    On both machines the References are te same.

    Any clue as to where to look next?

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    Step through the code and check all values as you go

    when you get to the for each line, in the immediate window type something like
    TOPSFolder.Items.Count

  3. #3
    TOPSie is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Mar 2021
    Posts
    108
    Quote Originally Posted by CJ_London View Post
    Step through the code and check all values as you go

    when you get to the for each line, in the immediate window type something like
    TOPSFolder.Items.Count
    I had already done this and the answer was 0. So the code wasn't crashing, simply wasn't finding the emails which were in the folder.

    My Outlook has multiple accounts, and it was definitley finding the right account. However the chosen account is a POP account.
    So I changed the default account (in Outlook as the code will pick up the default one automatically) and this account is an IMAP account.
    And now the code sees the email and everything is now fine

Please reply to this thread with any new information or opinions.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums