【问题标题】:Including Parenthisis inside a VBA db.Execute String在 VBA db.Execute String 中包含括号
【发布时间】:2015-05-22 13:48:15
【问题描述】:

如何正确格式化这行代码以允许我在语句字符串中包含括号?

db.Execute("SQL DB", "INSERT INTO ABPCahirMIS.dbo.TESTDB (TEST) VALUES(1)")

【问题讨论】:

  • 你到底是什么意思?您能否举例说明该语句的含义?
  • @Jeremy C. 当我运行它时,它告诉我在调用 sub 时不能使用括号?
  • 尝试在你的语句之前调用:调用 db.Execute("SQL DB", "INSERT INTO ABPCahirMIS.dbo.TESTDB (TEST) VALUES(1)")
  • 如果那个不起作用,您可能想阅读此内容:stackoverflow.com/questions/14902134/…
  • 如果调用的结果没有分配给变量,VBA 不希望在 Execute 调用周围加上外括号。

标签: sql vba string-formatting


【解决方案1】:

在VBA中,如果你调用一个sub,你不要在调用中添加括号,例如:

db.Execute "SQL DB", "INSERT INTO ABPCahirMIS.dbo.TESTDB (TEST) VALUES(1)"

【讨论】:

    【解决方案2】:

    类似这样的:

    Dim dbs As DAO.Database, sql as String
    Set dbs = "SQL DB"
    sql = INSERT INTO ABPCahirMIS.dbo.TESTDB (TEST) VALUES(1)
    dbs.Execute sql, dbFailOnError
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-14
      • 1970-01-01
      • 1970-01-01
      • 2016-09-14
      • 2015-11-28
      • 2015-10-01
      • 1970-01-01
      • 2014-06-15
      相关资源
      最近更新 更多