Link to home
Start Free TrialLog in
Avatar of Senniger1
Senniger1

asked on

Export from MS Access to Outlook Calendar

I have Office 2010.  In Access 2010 I have an access form named TimeOff.  I have a command button on this form that when clicked should determine which records have a check in the "Exported" field and then add each record to my Outlook 2010 Calendar.

The code I'm using (see below) are snippets I found and modified.  It doesn't exactly work, but is close.

Can anyone help me with this.


Dim outobj As Outlook.Application
Dim outappt As Outlook.AppointmentItem
Dim dbsCalendarTEST As DAO.Database
Dim rstTimeOff As DAO.Recordset
Dim strSQL As String
Dim intI As Integer

On Error GoTo ErrorHandler
   Set CalendarTEST = CurrentDb
   
   strSQL = "SELECT * FROM TimeOff WHERE Exported = true"
   Set rstTimeOff = CalendarTEST.OpenRecordset(strSQL, dbOpenDynaset)

    DoCmd.GoToRecord , , acFirst
   
        Set outobj = CreateObject("outlook.application")
        Set outappt = outobj.CreateItem(olAppointmentItem)
   
   intI = 1
   With rstTimeOff
      Do Until .EOF
      .Edit

        Set outobj = CreateObject("outlook.application")
        Set outappt = outobj.CreateItem(olAppointmentItem)
        With outappt
            .Start = Me!DateOff
            .Subject = Me!EmpInit
            .Body = Me!Comments
            .Save
        End With
         .Update
         .MoveNext
         intI = intI + 1
      Loop
   End With

   rstTimeOff.Close
   dbsCalendarTEST.Close

   Set rstTimeOff = Nothing
   Set dbsCalendarTEST = Nothing

   Exit Sub

ErrorHandler:
   MsgBox "Error #: " & Err.Number & vbCrLf & vbCrLf & Err.Description

Thanks in advance!
Avatar of Ken Butters
Ken Butters
Flag of United States of America image

It doesn't exactly work, but is close.

Need more detail.  What is working and what is not?
ASKER CERTIFIED SOLUTION
Avatar of Senniger1
Senniger1

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
SOLUTION
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 Senniger1
Senniger1

ASKER

I tried your suggestions but still got the error.  I ended up finding the following link and it worked.

https://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/A_4316-Automate-Outlook-in-VBA-with-the-OutlookCreateItem-Class.html

Since you tried to assist me I'll award you partial points.