Hi,
I am copying messages from outlook and transferring them into a table in access. I need the security alerts from Outlook to be turn off, as everytime an email is copied I have to click yes to allow access to copy the mail. Here is the code I have and I got three lines of code which should turn off this warning. But when I play it it says that an object is required. Please if anyone could help me, thanks Eileen![Smile :) :)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
Public Sub ImportOutlookItems()
Dim Olapp As Outlook.Application
Dim Olmapi As Outlook.NameSpace
Dim Olfolder As Outlook.MAPIFolder
Dim OlMail As Object
Dim OlMessage As Outlook.MailItem
Dim OlItems As Outlook.Items
Dim OlRecips As Outlook.Recipients
Dim OlRecip As Outlook.Recipient
Dim strSQL As String
Dim strReceivedTime As String
Dim strLastChecked As String
'Dim SubFolder As MAPIFolder
Dim Rst As Recordset
Set Rst = CurrentDb.OpenRecordset("tbl_Mail") 'Open table tblMail
'Create a connection to outlook
Set Olapp = CreateObject("Outlook.Application")
Set Olmapi = Olapp.GetNamespace("MAPI")
'Open the inbox
'Set Olfolder = Olmapi.GetSharedDefaultFolder("Mailbox - PSC-EMEA").Folders.Item(olFolderInbox)
'Set Olfolder = Olmapi.Folders.Item("Mailbox - PSC-EMEA").Folders.Item("Inbox")
Set Olfolder = Olmapi.GetDefaultFolder(olFolderInbox)
Set OlItems = Olfolder.Items
'HERE IS WHERE I HAVE THE PROBLEM......
OlSecurityManager.DisableOOMWarnings = True
On Error GoTo Finally
' ... any action with protected objects ...
Finally:
OlSecurityManager.DisableOOMWarnings = False
'Setting a variable to go through the emails
i = 1
'Here I am declaring two variables to compare the time from the Received mail in Outlook, with my column
'on the DB Last_Checked
For Each OlMail In OlItems
strReceivedTime = (Str(CDbl(DateValue(Format(OlMail.ReceivedTime, "dd-mmm-yyyy")))))
strLastChecked = CDbl(DateValue(Format(Rst!Last_Checked, "dd-mmm-yyyy")))
If strReceivedTime > strLastChecked And OlMail.UnRead = True Then
Rst.AddNew
Rst!Date = OlMail.ReceivedTime
Rst!Time = OlMail.ReceivedTime
Rst!From = OlMail.SenderName
Rst!Subject = OlMail.Subject
Rst!Body = OlMail.Body
Rst!CreationTime = OlMail.CreationTime
Rst!LastModificationTime = OlMail.LastModificationTime
Rst!Last_Checked = Now
Rst.Update
End If
i = i + 1
Next OlMail
MsgBox "New mails have been updated. Please check the tbl_Mail details", vbOKOnly
'Release memory
Set Olapp = Nothing
Set Olmapi = Nothing
Set Olfolder = Nothing
Set OlItems = Nothing
Set OlMail = Nothing
Set OlMessage = Nothing
End Sub
I am copying messages from outlook and transferring them into a table in access. I need the security alerts from Outlook to be turn off, as everytime an email is copied I have to click yes to allow access to copy the mail. Here is the code I have and I got three lines of code which should turn off this warning. But when I play it it says that an object is required. Please if anyone could help me, thanks Eileen
Public Sub ImportOutlookItems()
Dim Olapp As Outlook.Application
Dim Olmapi As Outlook.NameSpace
Dim Olfolder As Outlook.MAPIFolder
Dim OlMail As Object
Dim OlMessage As Outlook.MailItem
Dim OlItems As Outlook.Items
Dim OlRecips As Outlook.Recipients
Dim OlRecip As Outlook.Recipient
Dim strSQL As String
Dim strReceivedTime As String
Dim strLastChecked As String
'Dim SubFolder As MAPIFolder
Dim Rst As Recordset
Set Rst = CurrentDb.OpenRecordset("tbl_Mail") 'Open table tblMail
'Create a connection to outlook
Set Olapp = CreateObject("Outlook.Application")
Set Olmapi = Olapp.GetNamespace("MAPI")
'Open the inbox
'Set Olfolder = Olmapi.GetSharedDefaultFolder("Mailbox - PSC-EMEA").Folders.Item(olFolderInbox)
'Set Olfolder = Olmapi.Folders.Item("Mailbox - PSC-EMEA").Folders.Item("Inbox")
Set Olfolder = Olmapi.GetDefaultFolder(olFolderInbox)
Set OlItems = Olfolder.Items
'HERE IS WHERE I HAVE THE PROBLEM......
OlSecurityManager.DisableOOMWarnings = True
On Error GoTo Finally
' ... any action with protected objects ...
Finally:
OlSecurityManager.DisableOOMWarnings = False
'Setting a variable to go through the emails
i = 1
'Here I am declaring two variables to compare the time from the Received mail in Outlook, with my column
'on the DB Last_Checked
For Each OlMail In OlItems
strReceivedTime = (Str(CDbl(DateValue(Format(OlMail.ReceivedTime, "dd-mmm-yyyy")))))
strLastChecked = CDbl(DateValue(Format(Rst!Last_Checked, "dd-mmm-yyyy")))
If strReceivedTime > strLastChecked And OlMail.UnRead = True Then
Rst.AddNew
Rst!Date = OlMail.ReceivedTime
Rst!Time = OlMail.ReceivedTime
Rst!From = OlMail.SenderName
Rst!Subject = OlMail.Subject
Rst!Body = OlMail.Body
Rst!CreationTime = OlMail.CreationTime
Rst!LastModificationTime = OlMail.LastModificationTime
Rst!Last_Checked = Now
Rst.Update
End If
i = i + 1
Next OlMail
MsgBox "New mails have been updated. Please check the tbl_Mail details", vbOKOnly
'Release memory
Set Olapp = Nothing
Set Olmapi = Nothing
Set Olfolder = Nothing
Set OlItems = Nothing
Set OlMail = Nothing
Set OlMessage = Nothing
End Sub