Spurious输入ParameterValue消息

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

我有一个表单,其中包含一个名为StartDate的未绑定短日期字段和一个单击按钮,用于启动VBA代码,如下所示,我得到StartDate的“输入参数消息”。 StockTakeDate也是一个短期日期。任何有关摆脱信息的建议都会受到欢迎。

Private Sub cmdInventory_Click()

    strMsg = "Enter StartDate as Today's date or later"

    If Me.[StartDate] < Date Then 
        MsgBox strMsg, ExitSub 
    Else
        Dim strSQL
        strSQL = " UPDATE [Inventory] " _
            & " SET [Inventory].[InStock] = [Inventory].[StockTake] " _
            & " WHERE ([Inventory].[StockTakeDate] >= Me.[StartDate]) "
        DoCmd.RunSQL strSQL

End Sub
access-vba
2个回答
0
投票

使用Me.SomeField时不能使用DoCmd.RunSQL。相反,使用Forms!SomeForm!SomeField

Dim strSQL
strSQL = " UPDATE [Inventory] " _
         & " SET [Inventory].[InStock] = [Inventory].[StockTake] " _
         & " WHERE ([Inventory].[StockTakeDate] >= Forms!MyFormName![StartDate]) "
DoCmd.RunSQL strSQL

0
投票

连接格式化为字符串表达式的参数值(StartDate):

strSQL = " UPDATE [Inventory] " _
    & " SET [Inventory].[InStock] = [Inventory].[StockTake] " _
    & " WHERE ([Inventory].[StockTakeDate] >= #" & Format(Me![StartDate].Value, "yyyy\/mm\/dd") & "#"
DoCmd.RunSQL strSQL
© www.soinside.com 2019 - 2024. All rights reserved.