The following example opens a connection to an Exchange or
to an Outlook mailbox, and then prints out the subject and the date received
values of the first record in the Calendar.
NOTE: Steps 1 through 3 show you how to determine the name of your
mailbox. If you already know the name of your mailbox, go to step 4.
- Click Start, point to Settings, and then click Control Panel.
- In Control Panel, open the Mail tool.
- Click the Delivery tab to see the list of available mailboxes. Your mailbox name is
in the Deliver new mail to the following location box.
- In an Access database, create a new module, and then paste
or type the following code.
NOTE: In the connection string, change the name James Smith to your
mailbox name, and make sure the path to the Temp folder is correct for your
system. Keep in mind that the spaces, the minus sign, and the vertical bar
character are required in the string.
Sub OpenExchange_Calendar()
Dim ADOConn As ADODB.Connection
Dim ADORS As ADODB.Recordset
Dim strConn As String
Set ADOConn = New ADODB.Connection
Set ADORS = New ADODB.Recordset
With ADOConn
.Provider = "Microsoft.JET.OLEDB.4.0"
.ConnectionString = "Exchange 4.0;" _
& "MAPILEVEL=Mailbox - James Smith|;" _
& "PROFILE=MS Exchange Settings;" _
& "TABLETYPE=0;DATABASE=C:\WINDOWS\TEMP\;"
.Open
End With
With ADORS
.Open "Select * from Calendar", ADOConn, adOpenStatic, _
adLockReadOnly
.MoveFirst
Debug.Print ADORS(3).Name, ADORS(3).Value
Debug.Print ADORS(10).Name, ADORS(10).Value
.Close
End With
Set ADORS = Nothing
ADOConn.Close
Set ADOConn = Nothing
End Sub
- In the Immediate window, type the following line, and then
press ENTER:
Note that the name of the first contact in your contacts folder
appears in the Immediate window.