访问“如果/和/然后”发送电子邮件

问题描述 投票:0回答:1

我有一个访问数据库,并且在表单中,如果 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 ms-access outlook visio
1个回答
0
投票

在 VBA 中,不能将任何内容与 Null 进行比较,甚至不能与 Null 进行比较。

使用 IsNull() 函数:

If DaysLeft < 5 And IsNull(MoveOutPacket) Then

可能还想纠正拼写:receiveReceived

© www.soinside.com 2019 - 2024. All rights reserved.