Link to home
Create AccountLog in
Avatar of njm1888
njm1888

asked on

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

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!
ASKER CERTIFIED SOLUTION
Avatar of Chuck Wood
Chuck Wood
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of njm1888
njm1888

ASKER

That was it!  My partner and I were being dense in this area and could not find something that answered our question.  Thank you for the assistance!