【问题标题】:Debugging Access VBA Currentdb.Execute调试访问 VBA Currentdb.Execute
【发布时间】:2020-07-06 16:03:17
【问题描述】:

当我运行这段代码时,它说无效的插入语句。

CurrentDb.Execute "insert into invoices (Stateid, companyid, PaymentYear,InvoiceDate,Type,MethodofPayment,date,amount) " & _
"values('" & Me.StateID & "','cOOKIE','" & Me.PaymentYear & "', '" & Me.InvoiceDate & "'," _
& "'" & Me.Type & "','" & Me.MethodofPayment & "','" & Me.Date & "','" & Me.Amount & "');"

【问题讨论】:

标签: vba ms-access debugging


【解决方案1】:

首先,为值提供有效的字符串表达式 - 并非所有内容都是文本 - 并尊重保留字:

CurrentDb.Execute "insert into invoices (Stateid, companyid, PaymentYear, InvoiceDate, [Type], MethodofPayment, [date], amount) " & _
"Values('" & Me.StateID & "','cOOKIE'," & Me.PaymentYear & ", #" & Format(Me.InvoiceDate, "yyyy\/mm\/dd") & "#, " & _
"'" & Me.Type & "','" & Me.MethodofPayment & "',#" & Format(Me.Date, "yyyy\/mm\/dd") & "#," & Str(Me.Amount) & ");"

【讨论】:

  • 谢谢。我后来意识到了。
  • 或者使用我的CSql函数here.
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-22
  • 1970-01-01
  • 1970-01-01
  • 2015-07-14
相关资源
最近更新 更多