Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Access VBA - insert record data into Outlook calendar based on date

Hi

I have an Access table that contains three columns: "Date", "Time", "Description".
I want to use Access VBA to loop through the records and add each record
to the correct date (based on the "Date" field) at the correct time (based on the "Time" field). I want to then add the description to this calendar entry (based on the "Description" field.
Thank you
Avatar of shambalad
shambalad
Flag of United States of America image

Try the attached code.
Todd

Sub CreateCalendarItem(strSubject As String, strDate As String, strTime As String)
   Dim olkAppt As Outlook.AppointmentItem
   Dim OlkApp As Outlook.Application
   Dim dte As Date
   
   ' Must add Outlook to references for this to work
   dte = CDate(strDate & " " & strTime)
   
   Set OlkApp = New Outlook.Application
   With OlkApp
      Set olkAppt = .CreateItem(Outlook.OlItemType.olAppointmentItem)
      With olkAppt
         .Start = dte
         .Subject = strSubject
         .ReminderSet = False
         olkAppt.Save
      End With
   End With
   
   ' Clean up.
   Set OlkApp = Nothing
   Set olkAppt = Nothing
End Sub
 
Sub testCreateCalendarItem()
   Dim strSubject As String, strDate As String, strTime As String
   strSubject = "Create Menu Item in VBA"
   strDate = "5/20/2009"
   strTime = "8:30:00 PM"
   CreateCalendarItem strSubject, strDate, strTime
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of shambalad
shambalad
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Murray Brown

ASKER

Many thanks Todd.Great answer!
Avatar of hgj1357
hgj1357

How can you get a warning that Outlook isn't running? This code requires Outlook to be running, right?
My mistake! It just takes a few seconds to show up if the event was added with Outlook not running.

How would I add a contact? That would be pretty awesome!