forensicpsyguy
Programmer
I would like to modify the following code (from MS) to dynamically create a linked table to the current user's Outlook inbox. The database will have a few users, and I want to create this linked table on entry and delete the table prior to exit from the database.
Is it possible to write code to get the information needed for this procedure without user intervention? This procedure works fine as is, but I had to hardcode the necessary information. I would need to dynamically get:
-the "exchange mailbox name" for the current user
-the current path to the database (as that may change at some point
Remember, I want to delete the linked table upon exit from the form that uses it, or the database.
Is it possible to write code to get the information needed for this procedure without user intervention? This procedure works fine as is, but I had to hardcode the necessary information. I would need to dynamically get:
-the "exchange mailbox name" for the current user
-the current path to the database (as that may change at some point
Remember, I want to delete the linked table upon exit from the form that uses it, or the database.
Code:
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 - Stephens, Sam J LT NNMC|;"
'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=C:\Documents and Settings\sjstephens\My Documents\Intern Recruitment.mdb;"
'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=Default Outlook Profile"
'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