Avatar of caandal
caandal

asked on 

Check for emails from a particular domain in outlook via VBA - MS ACCESS

Hi Experts

I have a client who receives orders via email in outlook.  Because of the size of the client (i.e. many different divisions ) there is no set template or anything that gets used to request and order (the client is not interested in changing the way that they work) Is there anyway that I can retrieve the mail header / subject line into a table in VBA or SQL and then set a trigger for it to be processed?

Many thanks
Alan
OutlookMicrosoft AccessVBA

Avatar of undefined
Last Comment
caandal
Avatar of Jim Dettman (EE MVE)
Jim Dettman (EE MVE)
Flag of United States of America image

What are you using to interact with Outlook?

Jim.
Avatar of COACHMAN99
COACHMAN99

In Access: use External data \ More \ Outlook Folder.
then use a table data-macro or timer in Access to process new records.

In Outlook: code around the Application / ItemAdd event
e.g.
In this Visual Basic for Applications (VBA) example, when a new contact is added to the Contacts folder, the contact item is attached to an e-mail message and sent to a distribution list named "Sales Team". The sample code must be placed in a class module, and the Initialize_handler routine must be called before the event procedure can be called by Microsoft Outlook.

Public WithEvents myOlItems As Outlook.Items

 
Public Sub Initialize_handler()
 Set myOlItems = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderContacts).Items
End Sub
 
Private Sub myOlItems_ItemAdd(ByVal Item As Object)
 Dim myOlMItem As Outlook.MailItem
 Dim myOlAtts As Outlook.Attachments
 Set myOlMItem = myOlApp.CreateItem(olMailItem)
 myOlMItem.Save
 Set myOlAtts = myOlMItem.Attachments
 ' Add new contact to attachments in mail message
 myOlAtts.Add Item, olByValue
 myOlMItem.To = "Sales Team"
 myOlMItem.Subject = "New contact"
 myOlMItem.Send
End Sub
Avatar of caandal
caandal

ASKER

Hi Jim

It is an Access 2016 front end with a SQL backend
What I meant was how you were tied to Outlook; using CDO, vbMAPI, Outlook Redemption, or just talking straight to Outlook with OLE and dealing with the security warnings.

As Coachman showed, you can work with Outlook directly, but most use a 3rd party product (which have their own object models) to avoid security warnings.

Jim.
Avatar of caandal
caandal

ASKER

Hi Jim
At this stage nothing is in place - it would be relatively easy using a direct link to an outlook folder with OLE.  The issue that I have is retrieving attachments with the mails
ASKER CERTIFIED SOLUTION
Avatar of Jim Dettman (EE MVE)
Jim Dettman (EE MVE)
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
SOLUTION
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
SOLUTION
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of caandal
caandal

ASKER

Many thanks Jim - all looks good - your solutions have always worked for me in the past
Microsoft Access
Microsoft Access

Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.

226K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo