【问题标题】:Set statement error设置语句错误
【发布时间】:2015-10-01 13:51:49
【问题描述】:

我从下面的脚本中收到 3075 错误(无效的运算符)。 VBA 错误将 set 语句标记为黄色。我不明白为什么。缺少什么?

strSql = "SELECT FA_AVG.RadNr, (Left([Text],122)) AS LetaEfter1, Mid([Text],130,18) AS LetaEfter2, Right(Left([Text],184),36) AS LetaEfter3, FA_AVG.PerNr, FA_AVG.Fil, FA_AVG.GR1 " & _
"FROM FA_AVG " & _
"WHERE (((FA_AVG.RadNr)=20) AND ((Left([Text],122))='" & strTemp1 & "') AND ((Right(Left([Text],184),36))='" & strTemp3 & "') AND (Trim(FA_AVG.PerNr)='" & strPer & "'))"

Set rstAddData = CurrentDb.OpenRecordset(strSql)

【问题讨论】:

  • 什么是[文本]?那是表 FA_AVG 中的列还是某些文本框控件?您可能还想使用 SO 提供的代码 sn-p 工具来格式化您的代码以提高可读性。
  • 还有strTemp1、strTemp3和strPer的值是多少?它们不应该有撇号或任何可能破坏您构建的 sql 的非字母字符。

标签: ms-access vba


【解决方案1】:

运行它并研究输出,您可能会很清楚为什么它不会运行:

strSql = "SELECT FA_AVG.RadNr, (Left([Text],122)) AS LetaEfter1, Mid([Text],130,18) AS LetaEfter2, Right(Left([Text],184),36) AS LetaEfter3, FA_AVG.PerNr, FA_AVG.Fil, FA_AVG.GR1 " & _
"FROM FA_AVG " & _
"WHERE (((FA_AVG.RadNr)=20) AND ((Left([Text],122))='" & strTemp1 & "') AND ((Right(Left([Text],184),36))='" & strTemp3 & "') AND (Trim(FA_AVG.PerNr)='" & strPer & "'))"

Debug.Print strSQL

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-22
    • 2010-10-08
    • 2014-08-09
    • 1970-01-01
    • 1970-01-01
    • 2011-09-22
    相关资源
    最近更新 更多