air1access
Technical User
Below is code I'm working with.
It works just fine. BUT - I need to connect to a different inbox, and a folder in that inbox...
Right now it connects to the folder "HPMS" in MY inbox... But I need to connect to a different inbox - different folder in that inbox..
I can't figure it out...!!
any suggestions..?
Private Sub Form_Load()
'Import Email From The Inbox
Dim rst As Recordset
Dim db As Database
Dim strSearchString As String
Dim strSearchChar As String
Dim strChrPos As String
Dim strBaseMessage As String
'Set up Outlook Objects
Dim Outlook As New Outlook.Application
Dim OutlookNS As Outlook.Namespace
Dim cf As Outlook.MAPIFolder
Dim MyFolder As Outlook.MAPIFolder
Dim MailItem As Outlook.MailItem
Dim objItems As Outlook.Items
Dim iNumContacts As Integer
Dim i As Integer
Set db = CurrentDb()
Set rst = db.OpenRecordset("HPMS_eMails")
Set OutlookNS = Outlook.GetNamespace("MAPI")
Set cf = OutlookNS.GetDefaultFolder(olFolderInbox)
Set MyFolder = cf.Folders("HPMS")
Set objItems = MyFolder.Items
DoCmd.RunSQL "DELETE * FROM HPMS_eMails;"
iNumContacts = objItems.Count
If iNumContacts <> 0 Then
For i = 1 To iNumContacts
If TypeName(objItems(i)) = "MailItem" Then
Set MailItem = objItems(i)
If MailItem.Subject Like "Marketing Event Upload Submission Status*" Then
rst.AddNew
rst!Entry_ID = MailItem.EntryID
rst!Sender = MailItem.Sender
rst!Recieved = MailItem.ReceivedTime
rst!To = MailItem.To
rst!Subject = MailItem.Subject
rst!Body = MailItem.Body
rst!UnRead = MailItem.UnRead
rst.Update
End If
End If
Next i
rst.Close
'DisplayMessage "All Email Has Been Imported"
Else
DisplayMessage "There Is No Email To Be Imported"
End If
Me.lstEmails.Requery
It works just fine. BUT - I need to connect to a different inbox, and a folder in that inbox...
Right now it connects to the folder "HPMS" in MY inbox... But I need to connect to a different inbox - different folder in that inbox..
I can't figure it out...!!
any suggestions..?
Private Sub Form_Load()
'Import Email From The Inbox
Dim rst As Recordset
Dim db As Database
Dim strSearchString As String
Dim strSearchChar As String
Dim strChrPos As String
Dim strBaseMessage As String
'Set up Outlook Objects
Dim Outlook As New Outlook.Application
Dim OutlookNS As Outlook.Namespace
Dim cf As Outlook.MAPIFolder
Dim MyFolder As Outlook.MAPIFolder
Dim MailItem As Outlook.MailItem
Dim objItems As Outlook.Items
Dim iNumContacts As Integer
Dim i As Integer
Set db = CurrentDb()
Set rst = db.OpenRecordset("HPMS_eMails")
Set OutlookNS = Outlook.GetNamespace("MAPI")
Set cf = OutlookNS.GetDefaultFolder(olFolderInbox)
Set MyFolder = cf.Folders("HPMS")
Set objItems = MyFolder.Items
DoCmd.RunSQL "DELETE * FROM HPMS_eMails;"
iNumContacts = objItems.Count
If iNumContacts <> 0 Then
For i = 1 To iNumContacts
If TypeName(objItems(i)) = "MailItem" Then
Set MailItem = objItems(i)
If MailItem.Subject Like "Marketing Event Upload Submission Status*" Then
rst.AddNew
rst!Entry_ID = MailItem.EntryID
rst!Sender = MailItem.Sender
rst!Recieved = MailItem.ReceivedTime
rst!To = MailItem.To
rst!Subject = MailItem.Subject
rst!Body = MailItem.Body
rst!UnRead = MailItem.UnRead
rst.Update
End If
End If
Next i
rst.Close
'DisplayMessage "All Email Has Been Imported"
Else
DisplayMessage "There Is No Email To Be Imported"
End If
Me.lstEmails.Requery