Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用VBA从Access发送Outlook约会_Vba_Ms Access_Outlook - Fatal编程技术网

使用VBA从Access发送Outlook约会

使用VBA从Access发送Outlook约会,vba,ms-access,outlook,Vba,Ms Access,Outlook,我给工程师发电子邮件。我正在尝试访问以在他们的Outlook日历中设置提醒 我发现了一些看起来正确的东西。我删掉了我不需要的代码,剩下的就是这个 Option Compare Database Sub Outlook() Dim obj0App As Object Dim objAppt As Object Set obj0App = CreateObject("outlook.Application") Set objAppt = obj0App.CreateItem(olAppointme

我给工程师发电子邮件。我正在尝试访问以在他们的Outlook日历中设置提醒

我发现了一些看起来正确的东西。我删掉了我不需要的代码,剩下的就是这个

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导致

需要运行时错误424对象

为什么VBA不认可必需的和可选的与会者

注:
声明值的部分,这些值是:;EmailAddy、ASMail、qualifications电子邮件、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,代码停在
.requiredAttenders=EmailAddy.Value

运行时错误424,需要对象

如果我在错误恢复下一步添加
,并运行代码,我会收到一封电子邮件,其重要性作为正文详细信息(接受资格邮件)


监视列表上的
.requiredAttendes=EmailAddy.Value
表示表达式未在上下文中定义,上下文是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

唯一还没有起作用的是位置,所以我需要进一步研究这个问题,但大部分现在都起作用了。

你能把你的代码中声明
EmailAddy
ASMail
对象并为其赋值的部分添加到这个问题中吗。(我猜,
QualificationEmail
STdate
StTime
Edate
,以及
Location
对象)请阅读以下内容:--逐步浏览代码,检查变量。我强烈建议将它们放在每个模块的顶部。它强制执行变量声明,并在编译时报告未声明或拼写错误的变量/常量。要在新模块中自动执行此操作,请在VBA编辑器中设置该选项。这对于VBA开发来说确实是必须的。