A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Export email from Outlook into Access...



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old June 5th 09, 12:02 AM posted to microsoft.public.outlook.program_vba
EdEarnshaw
external usenet poster
 
Posts: 2
Default Export email from Outlook into Access...

I've come across some vba code allowing me to export emails from Outlook to
Access. It works wonderfully, except that repeating the operation adds
duplicate entries to the table in Access and forcing Access to not accept
duplicate entries stops the Outlook macro.

The reason I need to export out of Outlook stems from the fact that these
emails will be imported from several different Outlook accounts.

Is there any way to have the vba code check for duplicates before exporting
the emails, and if there are duplicates to export what is not a duplicate.

I'm using Outlook 2007 and Access 2007. The macro I'm using with Outlook is
as follows:

Sub ExportMailByFolder()
'Export specified fields from each mail
'item in selected folder.
Dim ns As Outlook.NameSpace
Dim objFolder As Outlook.MAPIFolder
Set ns = GetNamespace("MAPI")
Set objFolder = ns.PickFolder
Dim adoConn As ADODB.Connection
Dim adoRS As ADODB.Recordset
Dim intCounter As Integer
Set adoConn = CreateObject("ADODB.Connection")
Set adoRS = CreateObject("ADODB.Recordset")
'DSN and target file must exist.
adoConn.Open "DSN=OutlookData;"
adoRS.Open "SELECT * FROM email", adoConn, _
adOpenDynamic, adLockOptimistic
'Cycle through selected folder.
For intCounter = objFolder.Items.Count To 1 Step -1
With objFolder.Items(intCounter)
'Copy property value to corresponding fields
'in target file.
If .Class = olMail Then
adoRS.AddNew
adoRS("OutlookID") = .EntryID
adoRS("Subject") = .Subject
adoRS("Body") = .Body
adoRS("FromName") = .SenderName
adoRS("ToName") = .To
adoRS("FromAddress") = .SenderEmailAddress
adoRS("CCName") = .CC
adoRS("BCCName") = .BCC
adoRS("DateRecieved") = .ReceivedTime
adoRS("DateSent") = .SentOn
adoRS.Update
End If
End With
Next
adoRS.Close
Set adoRS = Nothing
Set adoConn = Nothing
Set ns = Nothing
Set objFolder = Nothing
End Sub
Ads
  #2  
Old June 8th 09, 01:09 PM posted to microsoft.public.outlook.program_vba
Michael Bauer [MVP - Outlook]
external usenet poster
 
Posts: 1,885
Default Export email from Outlook into Access...


Before calling adoRS.AddNew you can use the Find function and search for
whatever will identify the recordset for sure, for instance look whether or
not the EntryID already exists.

--
Best regards
Michael Bauer - MVP Outlook

: Outlook Categories? Category Manager Is Your Tool
: VBOffice Reporter for Data Analysis & Reporting
: http://www.vboffice.net/product.html?pub=6&lang=en


Am Thu, 4 Jun 2009 15:02:07 -0700 schrieb EdEarnshaw:

I've come across some vba code allowing me to export emails from Outlook

to
Access. It works wonderfully, except that repeating the operation adds
duplicate entries to the table in Access and forcing Access to not accept
duplicate entries stops the Outlook macro.

The reason I need to export out of Outlook stems from the fact that these
emails will be imported from several different Outlook accounts.

Is there any way to have the vba code check for duplicates before

exporting
the emails, and if there are duplicates to export what is not a duplicate.

I'm using Outlook 2007 and Access 2007. The macro I'm using with Outlook

is
as follows:

Sub ExportMailByFolder()
'Export specified fields from each mail
'item in selected folder.
Dim ns As Outlook.NameSpace
Dim objFolder As Outlook.MAPIFolder
Set ns = GetNamespace("MAPI")
Set objFolder = ns.PickFolder
Dim adoConn As ADODB.Connection
Dim adoRS As ADODB.Recordset
Dim intCounter As Integer
Set adoConn = CreateObject("ADODB.Connection")
Set adoRS = CreateObject("ADODB.Recordset")
'DSN and target file must exist.
adoConn.Open "DSN=OutlookData;"
adoRS.Open "SELECT * FROM email", adoConn, _
adOpenDynamic, adLockOptimistic
'Cycle through selected folder.
For intCounter = objFolder.Items.Count To 1 Step -1
With objFolder.Items(intCounter)
'Copy property value to corresponding fields
'in target file.
If .Class = olMail Then
adoRS.AddNew
adoRS("OutlookID") = .EntryID
adoRS("Subject") = .Subject
adoRS("Body") = .Body
adoRS("FromName") = .SenderName
adoRS("ToName") = .To
adoRS("FromAddress") = .SenderEmailAddress
adoRS("CCName") = .CC
adoRS("BCCName") = .BCC
adoRS("DateRecieved") = .ReceivedTime
adoRS("DateSent") = .SentOn
adoRS.Update
End If
End With
Next
adoRS.Close
Set adoRS = Nothing
Set adoConn = Nothing
Set ns = Nothing
Set objFolder = Nothing
End Sub

  #3  
Old June 15th 09, 10:27 PM posted to microsoft.public.outlook.program_vba
EdEarnshaw
external usenet poster
 
Posts: 2
Default Export email from Outlook into Access...

This helps, but I think I need a little more guidance as I do not know vba at
all and I'm not even sure what to be looking for.

I've added this line
adoRS.Find (OutlookID) Like .EntryID

but what do I actually need to be adding in code-wise that will keep the
macro from importing the duplicates.

Perhaps there is another solution to this problem that I'm not seeing.

"Michael Bauer [MVP - Outlook]" wrote:


Before calling adoRS.AddNew you can use the Find function and search for
whatever will identify the recordset for sure, for instance look whether or
not the EntryID already exists.

--
Best regards
Michael Bauer - MVP Outlook

: Outlook Categories? Category Manager Is Your Tool
: VBOffice Reporter for Data Analysis & Reporting
: http://www.vboffice.net/product.html?pub=6&lang=en


Am Thu, 4 Jun 2009 15:02:07 -0700 schrieb EdEarnshaw:

I've come across some vba code allowing me to export emails from Outlook

to
Access. It works wonderfully, except that repeating the operation adds
duplicate entries to the table in Access and forcing Access to not accept
duplicate entries stops the Outlook macro.

The reason I need to export out of Outlook stems from the fact that these
emails will be imported from several different Outlook accounts.

Is there any way to have the vba code check for duplicates before

exporting
the emails, and if there are duplicates to export what is not a duplicate.

I'm using Outlook 2007 and Access 2007. The macro I'm using with Outlook

is
as follows:

Sub ExportMailByFolder()
'Export specified fields from each mail
'item in selected folder.
Dim ns As Outlook.NameSpace
Dim objFolder As Outlook.MAPIFolder
Set ns = GetNamespace("MAPI")
Set objFolder = ns.PickFolder
Dim adoConn As ADODB.Connection
Dim adoRS As ADODB.Recordset
Dim intCounter As Integer
Set adoConn = CreateObject("ADODB.Connection")
Set adoRS = CreateObject("ADODB.Recordset")
'DSN and target file must exist.
adoConn.Open "DSN=OutlookData;"
adoRS.Open "SELECT * FROM email", adoConn, _
adOpenDynamic, adLockOptimistic
'Cycle through selected folder.
For intCounter = objFolder.Items.Count To 1 Step -1
With objFolder.Items(intCounter)
'Copy property value to corresponding fields
'in target file.
If .Class = olMail Then
adoRS.AddNew
adoRS("OutlookID") = .EntryID
adoRS("Subject") = .Subject
adoRS("Body") = .Body
adoRS("FromName") = .SenderName
adoRS("ToName") = .To
adoRS("FromAddress") = .SenderEmailAddress
adoRS("CCName") = .CC
adoRS("BCCName") = .BCC
adoRS("DateRecieved") = .ReceivedTime
adoRS("DateSent") = .SentOn
adoRS.Update
End If
End With
Next
adoRS.Close
Set adoRS = Nothing
Set adoConn = Nothing
Set ns = Nothing
Set objFolder = Nothing
End Sub


  #4  
Old June 20th 09, 04:27 PM posted to microsoft.public.outlook.program_vba
Michael Bauer [MVP - Outlook]
external usenet poster
 
Posts: 1,885
Default Export email from Outlook into Access...



Please use the ADO manual and see how the Find function works.

--
Best regards
Michael Bauer - MVP Outlook

: Outlook Categories? Category Manager Is Your Tool
: VBOffice Reporter for Data Analysis & Reporting
: http://www.vboffice.net/product.html?pub=6&lang=en


Am Mon, 15 Jun 2009 13:27:01 -0700 schrieb EdEarnshaw:

This helps, but I think I need a little more guidance as I do not know vba

at
all and I'm not even sure what to be looking for.

I've added this line
adoRS.Find (OutlookID) Like .EntryID

but what do I actually need to be adding in code-wise that will keep the
macro from importing the duplicates.

Perhaps there is another solution to this problem that I'm not seeing.

"Michael Bauer [MVP - Outlook]" wrote:


Before calling adoRS.AddNew you can use the Find function and search for
whatever will identify the recordset for sure, for instance look whether

or
not the EntryID already exists.

--
Best regards
Michael Bauer - MVP Outlook

: Outlook Categories? Category Manager Is Your Tool
: VBOffice Reporter for Data Analysis & Reporting
: http://www.vboffice.net/product.html?pub=6&lang=en


Am Thu, 4 Jun 2009 15:02:07 -0700 schrieb EdEarnshaw:

I've come across some vba code allowing me to export emails from Outlook

to
Access. It works wonderfully, except that repeating the operation adds
duplicate entries to the table in Access and forcing Access to not

accept
duplicate entries stops the Outlook macro.

The reason I need to export out of Outlook stems from the fact that

these
emails will be imported from several different Outlook accounts.

Is there any way to have the vba code check for duplicates before

exporting
the emails, and if there are duplicates to export what is not a

duplicate.

I'm using Outlook 2007 and Access 2007. The macro I'm using with Outlook

is
as follows:

Sub ExportMailByFolder()
'Export specified fields from each mail
'item in selected folder.
Dim ns As Outlook.NameSpace
Dim objFolder As Outlook.MAPIFolder
Set ns = GetNamespace("MAPI")
Set objFolder = ns.PickFolder
Dim adoConn As ADODB.Connection
Dim adoRS As ADODB.Recordset
Dim intCounter As Integer
Set adoConn = CreateObject("ADODB.Connection")
Set adoRS = CreateObject("ADODB.Recordset")
'DSN and target file must exist.
adoConn.Open "DSN=OutlookData;"
adoRS.Open "SELECT * FROM email", adoConn, _
adOpenDynamic, adLockOptimistic
'Cycle through selected folder.
For intCounter = objFolder.Items.Count To 1 Step -1
With objFolder.Items(intCounter)
'Copy property value to corresponding fields
'in target file.
If .Class = olMail Then
adoRS.AddNew
adoRS("OutlookID") = .EntryID
adoRS("Subject") = .Subject
adoRS("Body") = .Body
adoRS("FromName") = .SenderName
adoRS("ToName") = .To
adoRS("FromAddress") = .SenderEmailAddress
adoRS("CCName") = .CC
adoRS("BCCName") = .BCC
adoRS("DateRecieved") = .ReceivedTime
adoRS("DateSent") = .SentOn
adoRS.Update
End If
End With
Next
adoRS.Close
Set adoRS = Nothing
Set adoConn = Nothing
Set ns = Nothing
Set objFolder = Nothing
End Sub


 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Is it possible to export contacts from Outlook 07 into Access 07? bla50613 Outlook - Using Contacts 1 April 24th 08 03:31 AM
Export email and attachments to access fari Outlook - Using Forms 0 April 23rd 07 03:16 PM
Outlook Text Only Export into Access LI_SpeedyG Outlook and VBA 1 December 15th 06 06:12 PM
Outlook Web Access - Export Contacts?! RMarko Outlook - Using Contacts 4 December 6th 06 03:05 PM
Export Outlook 2003 Email Message To Access 2003 Table Gwhit Outlook and VBA 1 May 30th 06 05:36 PM


All times are GMT +1. The time now is 08:38 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.