Importing table data from outlook

Steve400

Registered User.
Local time
Today, 20:02
Joined
May 1, 2013
Messages
33
Hi,
I've got the following code to import email information from outlook into the database, however I'm getting the error: "The connection cannot be used to perform this operation. it is either closed or or invalid in this context"

I'm using Access 2007 with references: VB for applications, Outlook 12.0, OLE auto, Office 12.0, ActiveX data objects 6.1, access 12.0.

Any suggestions?
Thanks


Sub ExportToAccess()
Set ns = GetNamespace("MAPI")
Set objFolder = ns.PickFolder

Set adoConn = New ADODB.Connection
adoConn.Open "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\Users\HSC Staff\Desktop\StevesDatabase101.accdb"
Set adoRS = New ADODB.Recordset

With adoRS
.Open "SELECT * FROM Email, adoConn, , , adCmdText"
For i = objFolder.Items.Count To 1 Step -1
With objFolder.Items(i)
If .Class = olMail Then
adoRS.AddNew
adoRS("ToName") = .To
adoRS("Subject") = .Subject
adoRS("Body") = .Body
adoRS("FromName") = .SenderName
adoRS("FromAddress") = .SenderEmailAddress
adoRS("FromType") = .SenderEmailType
adoRS.Update
End If
End With
Next
End With

adoRS.Close
Set adoRS = Nothing
Set adoConn = Nothing
Set ns = Nothing
Set objFolder = Nothing
End Sub
 

Users who are viewing this thread

Back
Top Bottom