PC Review


Reply
Thread Tools Rate Thread

How to change this code to export to an existing database

 
 
DawnTreader
Guest
Posts: n/a
 
      6th Feb 2012
Hello All

I have a system already set up to import emails fields from outlook to access and it actually works really well. but it is reliant upon access pulling the information and i need to be the one to do it.

i would like to turn it around. i would like to have a little outlook addin that i can give to a few people that need it to allow them to hit the button and it would export the appropriate email fields to the existing access database.

i found this code:

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("Subject") = .Subject
adoRS("Body") = .Body
adoRS("FromName") = .SenderName
adoRS("ToName") = .To
adoRS("FromAddress") = .SenderEmailAddress
adoRS("FromType") = .SenderEmailType
adoRS("CCName") = .CC
adoRS("BCCName") = .BCC
adoRS("Importance") = .Importance
adoRS("Sensitivity") = .Sensitivity
adoRS.Update
End If
End With
Next
adoRS.Close
Set adoRS = Nothing
Set adoConn = Nothing
Set ns = Nothing
Set objFolder = Nothing
End Sub

but i can tell at a quick glance that it isnt "inserting" by calling a database by the file name and the table name in that database. can any one let me know if that is possible and what code i need to get it to connect with the database.

any and all help appreciated
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



Features
 

Advertising
 

Newsgroups
 


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