调试访问VBA Currentdb.Execute

时间:2018-06-20 15:59:00

标签: debugging access-vba access

运行此代码时,它说无效的插入语句。

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 & "');"

1 个答案:

答案 0 :(得分: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) & ");"