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.c om").Folde rs("Access _Received" )
Set olDestFolder = nms.Folders("User@OurURL.c om").Folde rs("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.c om").Folde rs("Access _Read")
Set olDestFolder = nms.Folders("User@OurURL.c om").Folde rs("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!
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.c
Set olDestFolder = nms.Folders("User@OurURL.c
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.c
Set olDestFolder = nms.Folders("User@OurURL.c
‘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
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER