At the risk of sounding too teacher-like, you should have at least tried to
take what I had and ran with it. My bad too, because I could have gave you
some general guidelines rather than code the whole solution for you, but I
simply can't resist...
'---------------------------------------------------------------------------------------
' Procedure : ExportCalendarToDatabase
' DateTime : 11/09/2006 19:44
' Author : Eric Legault [MVP - Outlook]
' Purpose : Exports Outlook Calendar items to an Access database.
' : Requires Reference to Microsoft ActiveX Data Objects 2.X Library
' : Assumes existence of these fields in a table named 'Calendar':
' : Subject (Text)
' : Contents (Memo)
' : Start (Date/Time)
' : End (Date/Time)
'
' Example Call:
' ExportCalendarToDatabase "C:\Test\db1.mdb"
'---------------------------------------------------------------------------------------
Sub ExportCalendarToDatabase(PathToAccessDB As String)
On Error GoTo ExportCalendarToDatabase_Error
Dim objFolder As Outlook.MAPIFolder, objItems As Outlook.Items
Dim objAppt As Outlook.AppointmentItem, objMessageObj As Object
Dim conThis As ADODB.Connection, rstThis As ADODB.Recordset
Set conThis = New ADODB.Connection
conThis.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
PathToAccessDB & ";Persist Security Info=False"
Set rstThis = New ADODB.Recordset
rstThis.Open "Calendar", conThis, adOpenDynamic, adLockOptimistic,
adCmdTable
MsgBox "Please select the Calendar that you want to export to Access
with the next dialog..." _
, vbOKOnly + vbInformation, "Export Calendar"
Set objFolder = Application.GetNamespace("MAPI").PickFolder
If objFolder.DefaultItemType <> olAppointmentItem Then
MsgBox "Invalid folder. Export aborted.", vbOKOnly + vbExclamation,
"Invalid Folder Type"
GoTo Exitt:
End If
Set objItems = objFolder.Items
For Each objMessageObj In objItems
If objMessageObj.Class = olAppointment Then
Set objAppt = objMessageObj
'SAVE TO ACCESS DATABASE
rstThis.AddNew
rstThis("Subject").Value = objAppt.Subject
'If the Body field is a memo data type, ensure that zero length
strings are allowed
If objAppt.Body <> "" Then rstThis("Contents").Value =
objAppt.Body
rstThis("Start").Value = objAppt.Start
rstThis("End").Value = objAppt.End
rstThis.UPdate
End If
Next
Exitt:
On Error Resume Next
Set rstThis = Nothing
conThis.Close
Set objFolder = Nothing
Set objItems = Nothing
Set objAppt = Nothing
Set objMessageObj = Nothing
On Error GoTo 0
Exit Sub
ExportCalendarToDatabase_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure
ExportCalendarToDatabase"
Resume Next
End Sub
--
Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog:
http://blogs.officezealot.com/legault/
Access101 said:
Eric,
I appreciated your advice on Importing Outlook from within Access, but as
you said, the key Start/End fields--along with meeting organizer--are not
included.
So I would appreciate being tweaked a little, to be able to include all
Outlook Calendar data: and then I’ll just query out unnecessary fields,
dates, etc. once inside Access.
But indeed I do need help tweaking. Along with any Tools, References that I
should have checked in Outlook to make this work.
Sub WriteEmailToDatabase()
Dim objFolder As Outlook.MAPIFolder, objItems As Outlook.Items
Dim objEmail As Outlook.MailItem, objMessageObj As Object
Dim dbsThis As DAO.Database, rstThis As DAO.Recordset
Set dbsThis = DAO.OpenDatabase("C:\Documents and
Settings\elegault\Desktop\db1.mdb")
Set rstThis = dbsThis.OpenRecordset("Table1", dbOpenDynaset)
Set objFolder = Application.ActiveExplorer.CurrentFolder
Set objItems = objFolder.Items
For Each objMessageObj In objItems
If objMessageObj.Class = olMail Then
Set objEmail = objMessageObj
'SAVE TO ACCESS DATABASE
rstThis.AddNew
rstThis("Subject") = objEmail.Subject
rstThis("Body") = objEmail.Body
rstThis.UPdate
End If
Next
End Sub