troubleshooting Question

Please help us connect access 2010 to outlook 365 using VBA.

Avatar of njm1888
njm1888 asked on
Microsoft AccessMicrosoft 365VB Script
2 Comments1 Solution1229 ViewsLast Modified:
Hello everyone, we have an Access 2010 custom application that is currently reading emails from a local Outlook application.  A VBA macro pulls text from the subject and body in each new email, which is then inserted into an Access table.  The VBA macro uses a SQL Script to do most of the work.

We would like to replace the connection to the local Outlook application with an Outlook 365 account.  We cannot find any information on the web regarding connecting Access 2010 to Outlook 365 using VBA.  Here is the current code with the connection to the local Outlook program:

Option Compare Database
    Dim oOutApp As Outlook.Application
    Dim nms As Outlook.NameSpace
    Dim olFrmFolders As Outlook.Folder
    Dim olDestFolder As Outlook.Folder
    Dim itm As Object
   

Public Function ImportNewOrders()
Set oOutApp = New Outlook.Application
Set nms = oOutApp.GetNamespace("MAPI")

‘Move to Folder  to Process Emails
Set olFrmFolders = nms.Folders("User@OurURL.com").Folders("Access_Received")
Set olDestFolder = nms.Folders("User@OurURL.com").Folders("Access_Read")

   For Each itm In olFrmFolders.Items
   itm.Move olDestFolder
   Next itm
 
‘Process Emails  
'Move to the Temp Table
 With DoCmd
  .SetWarnings False
  .OpenQuery "First Insert"
  .SetWarnings True
 End With

Set olFrmFolders = nms.Folders("User@OurURL.com").Folders("Access_Read")
Set olDestFolder = nms.Folders("User@OurURL.com").Folders("Access_Processed")

‘Move to the Completed Folder
    For Each itm In olFrmFolders.Items
    itm.Move olDestFolder
    Next itm
   
'Move to the Backend Table
  With DoCmd
  .SetWarnings False
  .OpenQuery "Second Insert"
  .SetWarnings True
  End With
 
'Clean Up the Temp Table
  With DoCmd
  .SetWarnings False
  .OpenQuery "Third Insert"
  .SetWarnings True
  End With

End Function

How can we change the Outlook.Application object to connect to our 365 account including the username and password information?

Thanks for your consideration!
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros