我有一个 Access 数据库,如果 DaysLeft 框小于 5 并且 MoveOutPacket 框为空,我希望从表单中触发一封电子邮件。
我有这个代码,但它没有通过电子邮件发送。
Private Sub DaysLeft_Change()
If (DaysLeft < 5) And (MoveOutPacket = Null) Then
Dim Msg As String
Msg = "Maintenance Team, we will recieve the keys for " & Property & " on " & Recieved_Keys & " please schedule cleaning and carpet cleaning if the unit is vacant."
Dim O As Outlook.Application
Dim M As Outlook.MailItem
Set O = New Outlook.Application
Set M = O.CreateItem(olMailItem)
With M
.BodyFormat = olFormatHTML
.HTMLBody = Msg
.To = "[email protected]"
.Send
End With
Set M = Nothing
Set O = Nothing
End If
End Sub
在 VBA 中,不能将任何内容与 Null 进行比较,甚至不能与 Null 进行比较。
使用 IsNull() 函数:
If DaysLeft < 5 And IsNull(MoveOutPacket) Then
可能还想纠正拼写:receive。