Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Dim objApp As Outlook.Application
Dim objNS As Outlook.Namespace
Dim objFolder As Outlook.MAPIFolder
Dim objItems As Outlook.Items
Dim objItem As Outlook.MailItem
Dim strFilter As String
Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")
'Get a reference to the Inbox
Set objFolder = objNS.GetDefaultFolder(olFolderInbox)
'Get the items in the Inbox
Set objItems = objFolder.Items
'Could filter at this point
'eg just unread items
'Set objItems = objFolder.Items.Restrict("[Unread] = True")
'eg a specific subject line
'Set objItems = objFolder.Items.Restrict("[Subject] = My target subject")
'eg items received after a certain date
'strLastUpd is a string passed in mm/dd/yyyy hh:mm:ss format
'where mm/dd/yyyy is the local short date format
'strFilter = "[ReceivedTime] > """# & strLastUpd & #""""
'Set objItems = objFolder.Items.Restrict(strFilter)
If Not objItems Is Nothing Then
'Connect to the SQL server here and create an ADODB recordset (rsTarget)
'Move through the items
For Each objItem in objItems
'Get the message body
strBody = objItem.Body
'Parse the data into fields, maybe pass the body and a UDT
'into your custom parsing function and return the parsed
'data in the udt - eg:
If fParseData(strBody, udtData) Then
'Data parsed successfully add a row to the recordset
rsTarget.AddNew
'Check for null string content
If udtData.Field1 <> vbNullString Then
rsTarget.Fields("Field1") = udtData.Field1
End If
'and so on for each field parsed from the message body
'Save the record
.Update
End If
Next
'Close connection and release ADODB object references
End If
'Release Outlook object references