B
Bob Dydd
I have got a stand alone PC running Window xp and Office 2000 and I am looking for a way to link to
my outlook inbox. I can do it easily enough using
1. select file
2. select Get external data
3. select Link tables
4. Go to the bottom of the dialog box that opens and select Files of
Type = Outlook
5. Select the Inbox. Bingo! It's done.
But now I want to be able to do it programmatically. I have found Microsoft Knowledge Base Article -
209946 but I am finding it difficult to follow as it seems to refer to Exchange folders rather than
Outlook.
My Office installation is the normal default for a stand alone machine and I am experimenting in the
Northwind.mdb which is installed in the samples folder that comes with Office 2000
I've scoured the web and this seems to be the closest to what is wanted.
I'd be grateful for any help or pointers
Bob Dydd
CODE FOLLOWS
Option Compare Database
Option Explicit
Function AttachMail()
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'This code requires that the following object library be referenced:
' Microsoft DAO 3.6 Object Library.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim db As DAO.Database
Dim td As DAO.TableDef
On Error GoTo Errorhandler
Set db = CurrentDb()
Set td = db.CreateTableDef("tblInbox")
'Within the following line, replace <mailbox name> with the actual
'Exchange mailbox name created on your computer. For example:
' Nancy Davolio
td.Connect = "Exchange 4.0;MAPILEVEL=Mailbox - <mailbox name>|;"
'Within the following line, replace <drive\path\dbname> with the
'actual path to the database. For example:
' C:\Program Files\Microsoft Office\Office\Samples\Northwind.mdb
'This will also support UNC (for example, \\servername\share\dbname).
td.Connect = td.Connect & "DATABASE=<drive\path\dbname>;"
'Within the following line, replace <profile name> with the actual
'name of your email profile created on your computer. For example:
' Microsoft Outlook
td.Connect = td.Connect & "PROFILE=<profile name>"
'Substitute the name of the email folder you wish to attach.
'In this example, we will attach the Inbox folder.
td.SourceTableName = "Inbox"
db.TableDefs.Append td
Application.RefreshDatabaseWindow
MsgBox "Table Appended!"
Exit Function
Errorhandler:
MsgBox "Error " & Err & " " & Error
Exit Function
End Function
Press CTRL+G to open the Immediate window, type the following line, and then press
ENTER:?AttachMail()
Note that after the procedure runs, the e-mail folder will be linked as a read-only table in the
database
my outlook inbox. I can do it easily enough using
1. select file
2. select Get external data
3. select Link tables
4. Go to the bottom of the dialog box that opens and select Files of
Type = Outlook
5. Select the Inbox. Bingo! It's done.
But now I want to be able to do it programmatically. I have found Microsoft Knowledge Base Article -
209946 but I am finding it difficult to follow as it seems to refer to Exchange folders rather than
Outlook.
My Office installation is the normal default for a stand alone machine and I am experimenting in the
Northwind.mdb which is installed in the samples folder that comes with Office 2000
I've scoured the web and this seems to be the closest to what is wanted.
I'd be grateful for any help or pointers
Bob Dydd
CODE FOLLOWS
Option Compare Database
Option Explicit
Function AttachMail()
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'This code requires that the following object library be referenced:
' Microsoft DAO 3.6 Object Library.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim db As DAO.Database
Dim td As DAO.TableDef
On Error GoTo Errorhandler
Set db = CurrentDb()
Set td = db.CreateTableDef("tblInbox")
'Within the following line, replace <mailbox name> with the actual
'Exchange mailbox name created on your computer. For example:
' Nancy Davolio
td.Connect = "Exchange 4.0;MAPILEVEL=Mailbox - <mailbox name>|;"
'Within the following line, replace <drive\path\dbname> with the
'actual path to the database. For example:
' C:\Program Files\Microsoft Office\Office\Samples\Northwind.mdb
'This will also support UNC (for example, \\servername\share\dbname).
td.Connect = td.Connect & "DATABASE=<drive\path\dbname>;"
'Within the following line, replace <profile name> with the actual
'name of your email profile created on your computer. For example:
' Microsoft Outlook
td.Connect = td.Connect & "PROFILE=<profile name>"
'Substitute the name of the email folder you wish to attach.
'In this example, we will attach the Inbox folder.
td.SourceTableName = "Inbox"
db.TableDefs.Append td
Application.RefreshDatabaseWindow
MsgBox "Table Appended!"
Exit Function
Errorhandler:
MsgBox "Error " & Err & " " & Error
Exit Function
End Function
Press CTRL+G to open the Immediate window, type the following line, and then press
ENTER:?AttachMail()
Note that after the procedure runs, the e-mail folder will be linked as a read-only table in the
database