简体   繁体   中英

Sending an Outlook appointment from Access using VBA

I send emails to engineers. I am trying to get Access to set a reminder in their Outlook calendar.

I found fromhttps://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.

Well after more trial and error, through the code I found that it wanted more declaring in Access, compared to Excel. In case anyone wants more info here is the code below:

Sub Outlook()
Dim obj0App As Object
Dim objAppt As Object
Dim EmailAddy As Object
Dim ASMail As Object
Dim QualificationEmail As Object
Dim STdate As Object
Dim StTime As Object
Dim Edate As Object
Dim Location As Object



Set obj0App = CreateObject("outlook.Application")
Set objAppt = obj0App.CreateItem(1) 'olAppointmentItem


With objAppt

.requiredattendees = Forms("EngTraining").EmailAddy.Value
.optionalattendees = Forms("EngTraining").ASMail.Value
.subject = "Training booked for " & " " &     Forms("EngTraining").QualificationEmail.Value
.Importance = 2 'high
.Start = Forms("EngTraining").STdate.Value & " " &     Forms("EngTraining").StTime.Value
.End = Forms("Engtraining").EngTrainsubform.EndDate.Value
'.Location = Location.Value
.ReminderMinutesBeforeStart = 20160 'reminder set for two weeks before     the event
.Body = "Training for" & " " &     Forms("EngTraining").QualificationEmail.Value     & "." & 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

The only thing that hasn't worked yet is location, so I need to look a little more into this, but the bulk of it works now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM