【问题标题】:What is the correct syntax for referencing a field with a hyphen?用连字符引用字段的正确语法是什么?
【发布时间】:2016-01-20 15:32:29
【问题描述】:

我有一个索引字段,如果在表单上尝试重复条目,我想为用户提供导航到原始记录的选项。我尝试了以下代码,改编自我发现的类似问题的答案here

在我的例子中,[BOL] 字段是一个可能包含多个连字符的文本字段。 Me.BOL 需要使用什么语法?例如,当我尝试在 BOL 字段中输入“CT-J17-XUSH-T001”时,出现错误:运行时错误“3070”:Microsoft Access 数据库引擎无法将“CT”识别为有效字段名称或表达式。

Private Sub BOL_BeforeUpdate(Cancel As Integer)


'https://stackoverflow.com/questions/14608052/prevent-duplicate-records-query-before-creating-new-records

Set rst = Me.RecordsetClone
rst.FindFirst "[ShipmentNumber] <> " & Me.ShipmentNumber & " AND [BOL] = " & Me.BOL
If Not rst.NoMatch Then
    Cancel = True
    If MsgBox("BOL already exists; goto existing record?", vbYesNo) = vbYes Then
        Me.Undo
        DoCmd.SearchForRecord , , acFirst, "[ShipmentNumber] = " & rst("ShipmentNumber")
    End If
End If
rst.Close

End Sub

【问题讨论】:

    标签: ms-access vba ms-access-2013


    【解决方案1】:

    在文本字段值周围添加单引号:

    rst.FindFirst "[ShipmentNumber] <> " & Me.ShipmentNumber & " AND [BOL] = '" & Me.BOL & "'"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-09-13
      • 1970-01-01
      • 2019-09-13
      • 1970-01-01
      • 2020-10-27
      • 2011-10-05
      • 1970-01-01
      相关资源
      最近更新 更多