Interface between Access 365 with Calendar in 365 Business

Are you saying you have two separate versions of Outlook installed? Or, were you actually referring to multiple Profiles or Accounts in one Outlook app?
Maybe the following picture clarifies the situation
1739426381429.png


"Outlook" is my original PST Outlook.
"johnpapaioannou@kosmosbusiness.onmicrosoft.com" is my trial Exchange based Outlook. Today I will add another Exchange Outlook.
 
I have two profiles - one is my personal archive for long-term storage. Turns out that many carriers would prefer that you remove your messages from their servers after a while, so I can drag-n-drop messages or use the "Move" option in the ribbon to get things to my archives and off the servers. However, my post-office base file matches my e-mail name, which is also The_Doc_Man, and my personal archive is Richard.
 
I added a third Outlook (second Exchange Outlook), as indicated below:
1739464314129.png


When I transfer the appointment info from the Access db to Outlook, all updates take place in the Outlook starting with "John.."
 
I set the default Outlook to the one beginning with "User1...", by going to File --> Account Settings.

When I now transfer the appointment info from the Access db to Outlook, all updates take place in the Outlook starting with "User1..."

So if we can find a way to set the default Outlook, we have a solution.
 
As well as finding the default folder, there must be a way to find another, for another account, if you know the account name or email address?
Edit: Read this thread
 
Last edited:
So if we can find a way to set the default Outlook, we have a solution.
That's not really necessary, but it's definitely one way to approach it.

Those things you see in Outlook could be all kinds of different objects like Mailboxes, Data Files, MS Teams Groups, SharePoint Lists, OneDrive Folders, etc. But in Outlook, they are all treated as Folders. To see what I mean, run the following code in Access and post the results.
Code:
Public Function GetOutlookFolders() As Boolean
'thedbguy@gmail.com
'2/13/2025

Dim olApp As Object
Dim nsMAPI As Object
Dim nsFolder As Object

Set olApp = CreateObject("Outlook.Application")
Set nsMAPI = olApp.GetNamespace("MAPI")

For Each nsFolder In nsMAPI.Folders
    Debug.Print nsFolder.Name
Next

Set nsFolder = Nothing
Set nsMAPI = Nothing
Set olApp = Nothing

End Function
 
That's not really necessary, but it's definitely one way to approach it.

Those things you see in Outlook could be all kinds of different objects like Mailboxes, Data Files, MS Teams Groups, SharePoint Lists, OneDrive Folders, etc. But in Outlook, they are all treated as Folders. To see what I mean, run the following code in Access and post the results.
Code:
Public Function GetOutlookFolders() As Boolean
'thedbguy@gmail.com
'2/13/2025

Dim olApp As Object
Dim nsMAPI As Object
Dim nsFolder As Object

Set olApp = CreateObject("Outlook.Application")
Set nsMAPI = olApp.GetNamespace("MAPI")

For Each nsFolder In nsMAPI.Folders
    Debug.Print nsFolder.Name
Next

Set nsFolder = Nothing
Set nsMAPI = Nothing
Set olApp = Nothing

End Function
Many thanks for your very useful post. The output is as follows:

user1@kosmosbusiness.onmicrosoft.com
Outlook
JohnPapaioannou@kosmosbusiness.onmicrosoft.com


The question remains as to how to write to a specific folder (Outlook), basically update a specific Calendar.
 
Last edited:
The question remains as to how to write to a specific folder (Outlook), basically update a specific Calendar.
Try this one out and let us know what happens.
Code:
Public Function CreateCalendarAppointment() as Boolean
'thedbguy@gmail.com
'2/14/2025

Dim olApp As Object
Dim nsMAPI As Object
Dim nsCalendar As Object
Dim calAppt As Object

Set olApp = CreateObject("Outlook.Application")
Set nsMAPI = olApp.GetNamespace("MAPI")
Set nsCalendar = nsMAPI.Folders("JohnPapaioannou@kosmosbusiness.onmicrosoft.com").Folders("Calendar")
Set calAppt = nsCalendar.Items.Add(1)

With calAppt
    .Subject = "Test Appointment"
    .Start = Now()
    .Duration = 60
    .Save
End With

Set calAppt = Nothing
Set nsCalendar = Nothing
Set nsMAPI = Nothing
Set olApp = Nothing

End Function
(untested)
 
Try this one out and let us know what happens.
Code:
Public Function CreateCalendarAppointment() as Boolean
'thedbguy@gmail.com
'2/14/2025

Dim olApp As Object
Dim nsMAPI As Object
Dim nsCalendar As Object
Dim calAppt As Object

Set olApp = CreateObject("Outlook.Application")
Set nsMAPI = olApp.GetNamespace("MAPI")
Set nsCalendar = nsMAPI.Folders("JohnPapaioannou@kosmosbusiness.onmicrosoft.com").Folders("Calendar")
Set calAppt = nsCalendar.Items.Add(1)

With calAppt
    .Subject = "Test Appointment"
    .Start = Now()
    .Duration = 60
    .Save
End With

Set calAppt = Nothing
Set nsCalendar = Nothing
Set nsMAPI = Nothing
Set olApp = Nothing

End Function
(untested)
Works like a charm. Can't thank you enough.

I was just reading about the Outlook model and was getting to the solution. The documentation is very verbose.
 
Last edited:
You're welcome. Good luck with your project.
There is no problem updating any Outlook and this works very well, especially with your help.

The challenge I am facing now is prior to the update, to be able to delete ALL entries of a specific day of a specific Outlook, so that when I do the update the Outlook would hold the latest data.

I will look into the Outlook model and hopefully find something.
 
There is no problem updating any Outlook and this works very well, especially with your help.

The challenge I am facing now is prior to the update, to be able to delete ALL entries of a specific day of a specific Outlook, so that when I do the update the Outlook would hold the latest data.

I will look into the Outlook model and hopefully find something.
That sounds very risky?
What if an entry was added manually, like a dentist appointment?
 
That sounds very risky?
What if an entry was added manually, like a dentist appointment?
Your concern is valid and raises a question.

If the Exchange Outlook for each dentist will be used to display the dentist's appointments as a read only feature then it is OK. If the user enters additional personal data, then there is a need to be able to delete all appointments that we copy over from the Access DB.

One way to solve this is to enter in the subject some character sequence ID which would indicate this.

So what is actually needed is to be able to deleted selected appointments. Thanks for pointing out the problem.
 
There is no problem updating any Outlook and this works very well, especially with your help.

The challenge I am facing now is prior to the update, to be able to delete ALL entries of a specific day of a specific Outlook, so that when I do the update the Outlook would hold the latest data.

I will look into the Outlook model and hopefully find something.
You will have to loop through each appointment and examine its contents. Or, maybe you could try to link to each calendar, so you can use a query.
 
You will have to loop through each appointment and examine its contents. Or, maybe you could try to link to each calendar, so you can use a query.
I can loop through each appointment. I will post the code. I have not figured out how to delete an appointment. One thing at a time :)
 
This is the code for deleting all appointments that have Location = 123

There is one problem. The following excerpt does not delete the last appointment. If there are 3 appointments it will delete 2 of the 3.

Code:
    For Each olAppointmentItem In olFilterAppointments
        Debug.Print olAppointmentItem.Subject, olAppointmentItem.Location
        If olAppointmentItem.Location = "123" Then
            olAppointmentItem.Delete
        End If
    Next



Code:
Private Sub Command89_Click()
Call subDeleteAutoGereratedAppointment(#2/16/2025 12:00:01 AM#, #2/16/2025 11:59:59 PM#, "user1@kosmosbusiness.onmicrosoft.com")
End Sub


Sub subDeleteAutoGereratedAppointment(dtmStart As Date, dtmEnd As Date, strOutlookEmail As String)
    Dim olApp              As Object
    Dim nsMAPI                   As Object
    Dim olAppointments         As Object
    Dim olFilterAppointments   As Object
    Dim olAppointmentItem      As Object
    Dim blnIsOutlookRunning        As Boolean
    Dim strDateRange As String


    On Error Resume Next
    Set olApp = GetObject(, "Outlook.Application")   
    If Err.Number <> 0 Then   
        Err.Clear
        Set olApp = CreateObject("Outlook.Application")
        blnIsOutlookRunning = False
    Else
        blnIsOutlookRunning = True   
    End If
    On Error GoTo Error_Handler
    DoEvents

    Set nsMAPI = olApp.GetNamespace("MAPI")
    Set olAppointments = nsMAPI.Folders(strOutlookEmail).Folders("Calendar")
    
    strDateRange = "[Start] >= '" & _
    Format$(dtmStart, "mm/dd/yyyy hh:mm AMPM") _
    & "' AND [Start] <= '" & _
    Format$(dtmEnd, "mm/dd/yyyy hh:mm AMPM") & "'"
    
    Set olFilterAppointments = olAppointments.Items.Restrict(strDateRange)
    Debug.Print olFilterAppointments.Count & " appointments found."
    'Iterate through each appt in our calendar
    For Each olAppointmentItem In olFilterAppointments
        Debug.Print olAppointmentItem.Subject, olAppointmentItem.Location
        If olAppointmentItem.Location = "123" Then
            olAppointmentItem.Delete
        End If
    Next

    If blnIsOutlookRunning = False Then    'Since we started Outlook, we should close it now that we're done
        olApp.Quit 'There seems to be a delay in this action taking place, but does eventually take place
    End If

Error_Handler_Exit:
    On Error Resume Next
    Set olAppointmentItem = Nothing
    Set olFilterAppointments = Nothing
    Set olAppointments = Nothing
    Set nsMAPI = Nothing
    Set olApp = Nothing
    Exit Sub

Error_Handler:
    MsgBox "The following error has occurred" & vbCrLf & vbCrLf & _
           "Error Number: " & Err.Number & vbCrLf & _
           "Error Source: GetFutureOutlookEvents" & vbCrLf & _
           "Error Description: " & Err.Description _
           , vbOKOnly + vbCritical, "An Error has Occurred!"
    Resume Error_Handler_Exit
End Sub
 
When deleting, best to start from the bottom and work backwards.
 

Users who are viewing this thread

Back
Top Bottom