I send emails to engineers. I am trying to get Access to set a reminder in their Outlook calendar.
I found from https://access-programmers.co.uk/forums/showthread.php?t=209552 something that looked correct. I cut out the code which I didn't require and this is what is left.
Option Compare Database
Sub Outlook()
Dim obj0App As Object
Dim objAppt As Object
Set obj0App = CreateObject("outlook.Application")
Set objAppt = obj0App.CreateItem(olAppointmentItem)
With objAppt
.requiredattendees = EmailAddy.Value
.optionalattendees = ASMail.Value
.subject = "Training booked for " & " " & QualificationEmail.Value
.Importance = 2 ' high
.Start = STdate.Value & "Starting at" & " " & StTime.Value
.End = Edate.Value
.Location = Location.Value
.Reminderminutesbeforestart = 20160 'reminder set for two weeks before the event
.Body = "Training for" & " " & [QualificationEmail] & "." & vbNewLine & "Any changes to this arrangement will be emailed to you. You will recieve any confirmation for bookings nearer the time."
.Meetingstatus = 1
.responserequested = True
.Save
.display
.send
MsgBox "Appointment sent"
End With
End Sub
When I test the code .requiredattendee is causing a
run-time error 424 Object Required.
Why is VBA not recognising required, and optional attendees?
Note:
The parts which are declaring values which are; EmailAddy, ASMail, QualificationsEmail, STdate, StTime, Edate & Location all link to an Access database form, using Dlookup's on text boxes like the examples below.
=DLookUp("[Engineer Email]","[EngTrainForm]","'[Windows ID]=" & [Windoze] & "'")
=[Forms]![Training_Admin]![Windows ID]
=DLookUp("[Area Of Work]","[EngTrainForm]","'[Windows ID]=" & [Windoze] & "'")
=DLookUp("[ASM Email]","[EngTrainForm]","'[Area]=" & [Area] & "'")
=DLookUp("[OutlookMSG]![Qualification]","[OutlookMSG]","' [EngTrain]! [Training Date Booked] =" & [EngDate] & "'")
When I step through, the olAppointmentItem = Empty and the code halts at .requiredattendees = EmailAddy.Value
bringing up
Run-Time error 424, Object required.
If I add an on error resume next
, and run through the code I get an email message with the Importance working as the Body details (accept the qualificationEmail).
The .requiredattendees = EmailAddy.Value
on the watch list is saying that the Expression is not defined in context, and the context is OutlookCalander,Outlook.
EmailAddy
andASMail
objects. (And, I guess, theQualificationEmail
,STdate
,StTime
,Edate
, andLocation
objects.) – YowE3KOption Explicit
at the top of each module. It enforces variable declaration and reports undeclared or misspelled variables/constants at compile time. To have this automatically in new modules, set the Require Variable Declaration option in the VBA Editor. This is really a must have for VBA development. – Andre