vba - 使用 VBA 从 Access 发送 Outlook 约会

标签 vba ms-access outlook

我向工程师发送电子邮件。我正在尝试让 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/

相关文章:

sql-server - MS Access 2019 - SQL Server 2017 - 记录集无法更新

excel - Excel 中的富文本格式(带有格式化标签)为无格式文本

excel - VB/VBA : Fetch HTML string from clipboard (copied via web browser)

php - 如何使用 PHP 将 mdb 文件转换为 mysql 文件或 mysql 命令?

sql - Access SQL : sum Sales of one Product for 2016 and 2017 in one sql-query

outlook - 以编程方式设置 Outlook 邮件项目的类别?

html - 对齐 HTML 表格以用于 outlook 电子邮件

javascript - 文件夹主页中的用户控件未初始化

excel - 保护工作表但取消保护文本输入形状

excel - 从工作表中的列表创建不重复的约会