我向工程师发送电子邮件。我正在尝试让 Access 在 Outlook 日历中设置提醒。
我从https://access-programmers.co.uk/forums/showthread.php?t=209552找到看起来正确的东西。我删除了不需要的代码,这就是剩下的。
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
当我测试代码时 .requiredattendee 导致
run-time error 424 Object Required.
为什么 VBA 无法识别必需的和可选的与会者?
注意:
声明值的部分是: EmailAddy、ASMail、QualificationsEmail、STdate、StTime、Edate 和 Location 都链接到 Access 数据库表单,在文本框中使用 Dlookup,如下例所示。
=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] & "'")
当我单步执行时,olAppointmentItem = Empty 并且代码在 .requiredattendees = EmailAddy.Value
启动时停止
Run-Time error 424, Object required.
如果我添加on errorresume next
,并运行代码,我会收到一封电子邮件,其中“重要性”作为正文详细信息(接受资格电子邮件)。
监视列表中的 .requiredattendees = EmailAddy.Value
表示表达式未在上下文中定义,上下文为 OutlookCalander,Outlook。
最佳答案
经过更多的尝试和错误,通过代码我发现与 Excel 相比,它需要在 Access 中进行更多声明。如果有人想了解更多信息,请使用以下代码:
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
唯一还没有起作用的是位置,所以我需要更多地研究这个,但现在大部分都起作用了。
关于vba - 使用 VBA 从 Access 发送 Outlook 约会,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44204635/