Create Outlook Appointment from VBA

Cavman

Registered User.
Local time
Today, 09:15
Joined
Oct 25, 2012
Messages
66
Hi,

I'm trying to create an Outlook appointment from VBA, but my code keeps throwing up a RunTime Error 438 - Object doesn't support this property or method. I'm guessing it's something simple, but I just can't figure it out! Here's the code:

Code:
Dim outApp As Object
    Dim outMail As Object
    Set outApp = CreateObject("Outlook.Application")
    Set outMail = outApp.CreateItem(olAppointmentItem)
        outMail.Subject = "Meeting room booked"
        outMail.Location = strBookingLocation
        outMail.MeetingStatus = olMeeting
        outMail.Start = dtBookingDate & " " & dtBookingTimeStart
        outMail.end = dtBookingDate & " " & dtBookingTimeEnd
        outMail.ReminderMinutesBeforeStart = 30
        outMail.ReminderSet = True
    outMail.Display
    outMail.Send
    Set outMail = Nothing
    Set outApp = Nothing

Thanks in advance for any help you can offer! :confused:
 
On which line do you get this error?

these two lines look suspect:

outMail.Start = dtBookingDate & " " & dtBookingTimeStart
outMail.end = dtBookingDate & " " & dtBookingTimeEnd

since you are assigning a string to a date, assuming dtBookingDate, etc are date types then try

outMail.Start = dtBookingDate + dtBookingTimeStart
outMail.end = dtBookingDate + dtBookingTimeEnd
 
Thanks for you reply CJ London.
Sorry, I didn't say did I? It's erroring as soon as I start trying to set the details of the appointment, ie. outMail.Subject = "Meeting room booked".
If I rem out that line, the next one errors, and so on. So I'm guessing there's something wrong with the set up of the Object?

Thanks
 
ok, an update: I've disabled all the lines from .Location to .ReminderSet and the code runs through without erroring. When it opens in Outlook, the object is a mail message, not and appointment. That would explain why the other properties won't work. So am I setting up the object wrong? How do I ensure it's an appointment that's created?
 
you need to add a constant in

CONST olAppointmentItem=1

I guess you developed with the outlook library and then removed to make late binding. olAppointmentItem is in the library, so is no longer declared in

Set outMail = outApp.CreateItem(olAppointmentItem)
 
That did the trick! Fantastic, thank you! :D
 
Hello

I am trying to create an Outlook Meeting Request inviting from the Outlook Address Book. I am able to create the appointment but cannot get it to invite anyone. Can someone please help?

Thanks

here is my code

Private Sub AddAppt_Click()
On Error GoTo AddAppt_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 already added to Microsoft Outlook"
Exit Sub
' Add a new appointment.
Else
Dim objFolder As Outlook.MAPIFolder
Dim objRecip As Outlook.Recipient
Dim strName As String
Dim outobj As Outlook.Application
Dim outappt As Outlook.AppointmentItem
Set outobj = CreateObject("outlook.application")
Set outappt = outobj.CreateItem(olAppointmentItem)
strName = Me!Assigned_To.Value
With outappt
.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
End With
End If
' Release the Outlook object variable.
Set outobj = Nothing
' Set the AddedToOutlook flag, save the record, display a message.
Me!AddedtoOutlook = True
DoCmd.RunCommand acCmdSaveRecord
MsgBox "Appointment Added!"
Exit Sub
AddAppt_Err:
MsgBox "Error " & Err.Number & vbCrLf & Err.Description
Exit Sub
End Sub
 

Users who are viewing this thread

Back
Top Bottom