一个简单的问题,我如何才能将在文本框中输入的内容从Access中输入到QuickBooks中。我在将Access连接到QuickBooks时没有问题,但是收到语法错误。
此硬编码输入有效:
sConnectString = "DSN=Quickbooks Data;OLE DB Services=-2;"
sSQL = "Insert into customer (Name) values ('Testing VB')"
Set oConnection = CreateObject("ADODB.Connection")
Set oRecordset = CreateObject("ADODB.Recordset")
oConnection.Open sConnectString
oConnection.Execute (sSQL)
sMsg = sMsg & "Record Added!!!"
MsgBox sMsg
Set oRecordset = Nothing
Set oConnection = Nothing
End Sub
这就是我要开始工作的内容(从文本框输入):
cust = Forms.form1.customerName
sConnectString = "DSN=Quickbooks Data;OLE DB Services=-2;"
sSQL = "Insert into customer (Name) values" & cust & ")"
Set oConnection = CreateObject("ADODB.Connection")
Set oRecordset = CreateObject("ADODB.Recordset")
oConnection.Open sConnectString
oConnection.Execute (sSQL)
sMsg = sMsg & "Record Added!"
MsgBox sMsg
Set oRecordset = Nothing
Set oConnection = Nothing
End Sub
更新(一次有多个条目是什么?
cust = Forms.form1.customerName
company = Forms.form1.companyName
sConnectString = "DSN=Quickbooks Data;OLE DB Services=-2;"
sSQL = "Insert into customer (Name), (CompanyName) values ('" & cust & "'), ('" & companyName & "') "
答案 0 :(得分:-1)
您没有正确形成动态SQL。您需要按照以下说明sSQL = "Insert into customer (Name) values ('" & cust & "')"
来调整代码,注意要用括号括起来的值和文本限定符引号。