Microsoft Graph API with Maria Barnes
With Microsoft actively removing COM/VBA support from "New Outlook," Maria Barnes' Graph API solution offers Access developers a forward-compatible pathway to maintain email integration when traditional Outlook automation becomes unavailable.
In her presentation at Access DevCon Vienna, Microsoft MVP Maria Barnes demonstrated how to integrate Microsoft Graph API with VBA applications, providing a robust method to interact with Microsoft 365 services like Outlook and Microsoft Entra ID (formerly Azure Active Directory). Her solution, published as an open-source project on GitHub, offers Access developers a way to create, read, and manage emails, calendar events, and contacts programmatically through authenticated API calls rather than through traditional automation.
Whether you're looking to send automated emails after reports are generated, manage contacts from your Access application, or integrate calendar functionality into your database, this technical deep dive provides the foundation you need to leverage Microsoft's powerful cloud services through the Graph API.
Understanding Microsoft Graph API
What is Microsoft Graph?
- Gateway to data and intelligence in Microsoft cloud services
- Connects to Microsoft 365 platform components (Outlook, SharePoint, OneDrive, etc.)
- Named for how it creates connections between different services
- Completely unrelated to charting in Access
Available Functionality
- Email operations (create drafts, send messages)
- Calendar management (create events)
- Contact management (retrieve and create contacts)
- User management through Microsoft Entra ID
- Many other Microsoft 365 services accessible through the same API
Authentication: The Most Challenging Part
Microsoft Entra ID Setup
- Requires administrative access to Microsoft Entra ID
- Need one of these roles: Application Administrator, Application Developer, or Cloud Application Administrator
- Application must be registered in Microsoft Entra ID portal
- Registration generates Client ID and Tenant ID needed for authentication
Six-Step Setup Process
- Go to Microsoft Entra ID in portal.azure.com
- Add an app registration with a descriptive name
- Copy the Client ID and Tenant ID values
- Add a redirect URI
- Select "Mobile and desktop applications" platform
- Choose the "Microsoft online native client" for OAuth 2.0
Authentication Flow
- Two-step process to acquire a token:
- Authenticate with Microsoft to get an authorization code
- Exchange that code for a token
- Uses an Edge browser control for the authentication process
- Tokens expire after 60-90 minutes
- Project includes logic to automatically refresh expired tokens
Technical Implementation
Project Components
- Graph Authenticator class module (adapted from Tim Hall's VBA Web Tools)
- Graph module for API calls
- Edge browser control for authentication
- Admin table to store configuration settings
- Forms to demonstrate API functionality
Key Functions Implemented
- Create draft email message
- Send email message
- Create calendar event
- List all contacts from a specific folder
- Get folder ID
- Create a contact
Usage Pattern
- Call a Graph API function
- Function triggers authentication if needed
- Authentication returns a token
- Token is used to make the actual API call
- JSON response is processed and converted to usable data
JSON Handling
- Uses Tim Hall's dictionary/collection implementation
- Parses JSON responses into Access tables
- Forms display the returned data
Sample Use Cases
Email Management
- Send automated emails after reports run
- Notify users when workflow statuses change
- Create draft emails programmatically
Contact Management
- Synchronize contacts between Access and Outlook
- Retrieve contact information for use in applications
- Create new contacts from Access data
Calendar Integration
- Create appointments based on Access data
- Schedule events programmatically
- Integrate with business workflows
Limitations and Considerations
Current Constraints
- Requires Microsoft 365/Exchange Online (won't work with Gmail/Google Workspace)
- May have issues with multi-factor authentication
- Draft messages appear in Outlook but don't automatically open
- Token lifetime is limited (60-90 minutes)
Technical Requirements
- Edge browser must be available
- Access to Microsoft Entra ID for initial setup
- Proper permissions in the Microsoft 365 environment
Resources and Documentation
Available Resources
- GitHub repository with complete source code
- Microsoft Graph API reference documentation
- Sample code for each API function
- Tim Hall's VBA Web Tools for additional reference
Finding API Documentation
- Microsoft's Graph API explorer
- API reference with examples at graph.microsoft.com
- Documentation includes required permissions and sample JSON
Conclusion
Maria Barnes' Graph API integration demonstrates a powerful alternative to the Outlook Object Model for Access developers needing to interact with Microsoft 365 services. By leveraging modern authentication and REST API calls, this approach provides a more robust and flexible way to work with emails, contacts, and calendar events directly from Access applications while avoiding many of the pitfalls of traditional Outlook automation.
Access to Recordings
This presentation was part of Access DevCon Vienna, a paid online conference for Microsoft Access developers. The full recording and other conference materials are exclusively available to registered attendees of the conference.
If you attended Access DevCon Vienna, you should have received an email from the conference organizers with a link to the videos.
Consider Attending Future Conferences
The quality and depth of content from Access DevCon Vienna demonstrates the value of professional development conferences focused on Microsoft Access. Consider attending future conferences to:
- Learn advanced techniques directly from expert presenters
- Gain access to exclusive content not available elsewhere
- Ask questions of expert presenters and other attendees
- Stay current with the latest Access development trends and best practices
For information about upcoming Access DevCon Vienna conferences, visit donkarl.com.
Referenced GitHub Projects
Acknowledgements
- Initial draft generated by Claude-3.7-Sonnet