Access Data to Outlook Calendar Appointment VBA Code Issues? (1 Viewer)

salt

New member
Local time
Today, 08:18
Joined
Aug 2, 2017
Messages
2
Hi, I'm a complete novice at VBA and coding in general. I've only made a few simple databases.

I am using Outlook 2010 and Access 2010. The calendar is Microsoft exchange.

I was hoping that I could have one of my databases add appointments to outlook or at least open outlook and have the appointment up with the date/time/address filled in?

I had a look around and found this code below that seems to be what I need. I tried it by adding it as an event procedure to a button on a form and edited it to fit my fields. However when I click on the button it comes back with:

"Compile error: user-defined type not defined" and it highlights the first line. Am I being really daft and gone about this the wrong way or do I need to edit the code??
:confused:

Any advice would be appreciated! :)

Code:
Private Sub AddtoOutlook_Click()

            Dim outobj As Outlook.Application
            Dim outappt As Outlook.AppointmentItem
            Set outobj = CreateObject("outlook.application")
            Set outappt = outobj.CreateItem(olAppointmentItem)
            With outappt
               .Start = Me.[Date of Training]
               .Duration = Me.[Duration]
               .Subject = Me.[Type of Training]
               .Save
               
            End With

         Set outobj = Nothing
         DoCmd.RunCommand acCmdSaveRecord
         MsgBox "Appointment Added!"
         
      Exit Sub


End Sub
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 15:18
Joined
May 7, 2009
Messages
19,230
On vbe make a referwnce to ms outlook library.
 

salt

New member
Local time
Today, 08:18
Joined
Aug 2, 2017
Messages
2
Thanks for your reply! Unfortunately I don't understand where I am meant to put the reference? I have never used VBA before so if you could possibly explain this it would be most appreciated.

Thanks!
 

new2access2018

New member
Local time
Today, 04:18
Joined
Nov 21, 2017
Messages
1
salt,

Go to the Database Tools tab, then in the Macro group select Visual Basic. On the Visual Basic window go to Tools then click on References. On the References window look for Microsoft Outlook 16.0 (or the version you have) Object Library, tick the box then click Accept and you're pretty much done.

I hope this helps
 

Users who are viewing this thread

Top Bottom