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

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


   Set rstTimeOff = Nothing
   Set dbsCalendarTEST = Nothing

   Exit Sub

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

Thanks in advance!
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ken ButtersCommented:
It doesn't exactly work, but is close.

Need more detail.  What is working and what is not?
Senniger1Author Commented:
It puts an entry into my calendar for each record checked as Exported, but all entries are the first entry duplicated x number of times.

Then I get and Error #:91 - Object variable or With block variable not set.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ken ButtersCommented:
duplicated entries:

rstTimeOff is your recordset that holds your data to create each new appointment

Each of these lines should refer to a field in the returned recordset.
           .Start = Me!DateOff
            .Subject = Me!EmpInit
            .Body = Me!Comments

something like this:
           .Start = rstTimeOff(0)
            .Subject = rstTimeOff(1)
            .Body = rstTimeOff(2)

your object or variable not set is probably due to this line:


you never set dbsCalendarTEST to an object, so you cannot close it.

I think you have a mixture of CalendarTEST and dbsCalendarTEST, but really meant for them to be the same variable.  You probably need to rename one of them or the other.
Senniger1Author Commented:
I tried your suggestions but still got the error.  I ended up finding the following link and it worked.


Since you tried to assist me I'll award you partial points.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.