Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disabling Outlook Warnings 1

Status
Not open for further replies.

eilob

Programmer
Mar 28, 2007
54
IE
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 :)

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
 
Hi Eileen,

I came accross your code and was very curious about it. It is something that I am interested in doing myself... I am still learning this stuff so you are probably way more experienced than I am.

I use Click yes as Tom Indicated However I did not use it when I tried to use your code....

There is stuff to Iron out because I removed alot of things just to get it to work..... It did work by the way with no warnings without click yes... Its not perfect.. still trying to figure it out myself....

Its your code with some things removed...... But it did work for me Just needs some reworking...

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......


On Error GoTo Finally
' ... any action with protected objects ...
Finally:



'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")))))




If strReceivedTime > strLastChecked And OlMail.UnRead = True Then

Rst.AddNew
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
 
Toms click yes works great, some of the code i posted work, but certain parts dont, as the part where I am trying to compare the received date with a column date on my table in Access. Hope it can be of good use for you.





 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top