一次读取 VBA 中的多个文本框条目时出现问题
Issue with reading multiple text box entries in VBA at once
一个简单的问题,我怎样才能将文本框中输入的内容从 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 & "') "
你没有正确形成动态SQL。您需要按如下方式调整您的代码 sSQL = "Insert into customer (Name) values ('" & cust & "')"
记下值周围的额外括号,以及文本限定符引号。
一个简单的问题,我怎样才能将文本框中输入的内容从 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 & "') "
你没有正确形成动态SQL。您需要按如下方式调整您的代码 sSQL = "Insert into customer (Name) values ('" & cust & "')"
记下值周围的额外括号,以及文本限定符引号。