Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming VBA / December 2006

Tip: Looking for answers? Try searching our database.

How to program to export certain Outlook 2000 messages to Access 2000 database

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Oscar - 19 Dec 2006 19:16 GMT
I would like to export certain messages from my inbox to an Access
2000 database.

I do it manually by Files | Export, etc.

Please explain how to use the Outlook object model to do this via VB
or point me to an example on the web.

Thank you in advance.
Michael Bauer [MVP - Outlook] - 20 Dec 2006 05:08 GMT
This sample loops through the inbox:

Dim obj as Object
Dim Mail as Outlook.MailItem
Dim Folder as Outlook.Mapifolder
Dim Items as outlook.Items

Set Folder=Applcation.GetNamespace("Mapi").GetDefaultFolder(olFolderInbox)
Set Item=Folder.Items
For Each obj in Items
    If TypeOf obj is Outlook.MailItem then
        Set Mail=obj
        ' go on here
    Endif
Next

You can view the MailItem's properties with the Object Browser (F2). Switch
from <All Libraries> to Outlook and select the MailItem in the left pane.

This sample connects to an Access database with ADO. You need to add a
reference to 'Microsoft ActiveX Data Objects x' to your project:

 Dim cn As ADODB.Connection
 Dim rs As ADODB.Recordset
 
 Set cn = New ADODB.Connection
 With cn
   .Provider = "Microsoft.Jet.OLEDB.4.0"
   .ConnectionString = "D:\test.mdb"
   .CursorLocation = adUseClient
   .Mode = adModeShareDenyNone
   .Open
 End With

 Set rs = New ADODB.Recordset
 With rs
   .CursorLocation = adUseClient
   .CursorType = adOpenStatic
   .LockType = adLockOptimistic
   Set .ActiveConnection = cn
   .Open ("select [field list] from [table]")
 End With

 rs.Close
 cn.Close

You can use the connection's Execute command with the Insert or Update
statement to add/update single records (then the recordset isn't necessary),
or work with the recordset.

Signature

Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
 Keep your Outlook categories organized!
 http://www.shareit.com/product.html?productid=300120654&languageid=1
 (German: http://www.VBOffice.net/product.html?pub=6)

Am Tue, 19 Dec 2006 14:16:58 -0500 schrieb Oscar:

> I would like to export certain messages from my inbox to an Access
> 2000 database.
[quoted text clipped - 5 lines]
>
> Thank you in advance.
Oscar - 20 Dec 2006 22:56 GMT
I know how to do all of this already.  The only place you address my
question is the line where you say "go on here"

I found a web site that says that the Outlook object model does not
allow access to the save as database file type command.

That website suggest automation of outlook with use of the SENDKEYS
command.

Thanks.

>This sample loops through the inbox:
>
[quoted text clipped - 45 lines]
>statement to add/update single records (then the recordset isn't necessary),
>or work with the recordset.
Michael Bauer [MVP - Outlook] - 21 Dec 2006 05:09 GMT
How helpful a precise question is, isn't it?

I wouldn't recommend the use of SendKeys. It sends the commands to the
window with the focus, and you never know which one that is.

At the 'go on here' line simply read the item's properties and write them
into the recordset, or build a Insert statement.

Signature

Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
 Keep your Outlook categories organized!
 http://www.shareit.com/product.html?productid=300120654&languageid=1
 (German: http://www.VBOffice.net/product.html?pub=6)

Am Wed, 20 Dec 2006 17:56:19 -0500 schrieb Oscar:

> I know how to do all of this already.  The only place you address my
> question is the line where you say "go on here"
[quoted text clipped - 56 lines]
>>statement to add/update single records (then the recordset isn't necessary),
>>or work with the recordset.
Oscar - 21 Dec 2006 18:43 GMT
>How helpful a precise question is, isn't it?

Maybe you didn't catch it but the precise question asked was:

"I do it manually by Files | Export, etc."

"Please explain how to use the Outlook object model to do this via VB
or point me to an example on the web."
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.