访问VBA检查日期时间,如果大于今天的3:00 PM,则出现vb问题错误消息

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

我有一个带有提交按钮的请求表。点击后,我想访问一下提交日期,以查看它是否大于今天的下午3:00。如果是,那么将显示一个消息框,供您更改请求的日期并重新提交。

这是我尝试过的,但出错了。

如果可能,请协助

Dim mDate As Date
mDate = DateValue(Me.tblEntered)
IIf (mDate > "3:00 pm")
    If MsgBox("You are submitting a request after the 3:00 PM cutoff time. " & Chr(13) & _
    "You should change your request to the next day.  Do you want to change your request date?", vbYesNo + vbQuestion + vbDefaultButton2) = vbNo Then
    DoCmd.Save
Else
    MsgBox "Please make changes and resubmit"
End If
access-vba access
1个回答
0
投票

您的代码存在一些错误(缺少“ End If”,使用“ IIf”而不是“ If”,日期检查是/否)

我不知道您来源的格式/内容:Me.tblEntered是一个日期还是日期和时间?如果包含时间,请更改我的“日期+#3:00:00 PM#”

Dim mDate As Date
mDate = DateValue(Me.tblEntered)

If (mDate > Date + #3:00:00 PM#) Then       ' Today at 3PM
    If MsgBox("You are submitting a request after the 3:00 PM cutoff time. " & Chr(13) & _
        "You should change your request to the next day.  Do you want to change your request date?", vbYesNo + vbQuestion + vbDefaultButton2) = vbNo Then
        DoCmd.Save
    Else
        MsgBox "Please make changes and resubmit"
    End If
End If
© www.soinside.com 2019 - 2024. All rights reserved.