linking Outlook calender to Access

battenberg

Burning candles both ends
Local time
Today, 23:48
Joined
Sep 25, 2006
Messages
118
Hi, after searching through the threads on this forum I found the following code:

Code:
cmdAddAppt_Click()
On Error GoTo Add_Err

'Save record first to be sure required fields are filled.
DoCmd.RunCommand acCmdSaveRecord

'Exit the procedure if appointment has been added to Outlook.
If Me!AddedToOutlook = True Then
MsgBox "This appointment is already added to Microsoft Outlook"
Exit Sub
'Add a new appointment.
Else
Dim objOutlook As Outlook.Application
Dim objAppt As Outlook.AppointmentItem
Dim objRecurPattern As Outlook.RecurrencePattern

Set objOutlook = CreateObject("Outlook.Application")
Set objAppt = objOutlook.CreateItem(olAppointmentItem)

With objAppt
.Start = Me!ApptDate & " " & Me!ApptTime
.Duration = Me!ApptLength
.Subject = Me!Appt

If Not IsNull(Me!ApptNotes) Then .Body = Me!ApptNotes
If Not IsNull(Me!ApptLocation) Then .Location = Me!ApptLocation
If Me!ApptReminder Then
.ReminderMinutesBeforeStart = Me!ReminderMinutes
.ReminderSet = True
End If

.Save
.Close (olSave)
End With
'Release the AppointmentItem object variable.
Set objAppt = Nothing
End If

'Release the Outlook object variable.
Set objOutlook = Nothing

'Set the AddedToOutlook flag, save the record, display a message.
Me!AddedToOutlook = True
DoCmd.RunCommand acCmdSaveRecord
MsgBox "Appointment Added!"

Exit Sub

Add_Err:
MsgBox "Error " & Err.Number & vbCrLf & Err.Description
Exit Sub
End Sub

This is my first attempt at trying to get outlook to intergrate with access, this code does not seem to work and falls over @
Dim objOutlook As Outlook.Application

Can anyone help me with a method of adding an entry to the outlook calender?? There is very little on this.....
 
I can't speak to most of this as I haven't gotten in too deep with using Outlook and Access together. But, what it appears to me is that you are using the Dim objOutlook As Outlook.Application (early binding) but using the late binding method of creating - Set objOutlook = CreateObject("Outlook.Application").

If you are going to use the Dim objOutlook as Outlook.Application, then you need to set a reference to Outlook prior to using it. If you want to use the late binding method so that you don't need to set the reference, then you would Dim objOutlook as Object and then use the CreateObject method. Otherwise using the early binding you should probably be using Set objOutlook = New Outlook.Application as the code.
 

Users who are viewing this thread

Back
Top Bottom