我有一个名为lstAvailable的列表框,我正在尝试将从中选择的值发送到表中。但我得到一个错误说Insert Into语句中的语法错误。机器子系统ID,NewComponents的类型为整数,MO_TAG和Components_Detail的文本类型为
Dim varItem As Variant
Dim sSQL As String
Dim nRid As Long
Dim nEid As Long
Dim nEid1 As String
Dim nEid2 As String
Dim varRow As Variant
nRid = listMachineSubSystem.Column(1)
For Each varRow In lstAvailable.ItemsSelected
nEid = lstAvailable.Column(0, varRow)
nEid1 = lstAvailable.Column(2, varRow)
nEid2 = lstAvailable.Column(3, varRow)
sSQL = "INSERT INTO tblComponents ([Machine Subsystem ID], [NewComponents], [MO_TAG], [Components_Detail])" _
& " VALUES (" & nRid & ", " & nEid & ", " & nEid1 & ", " & nEid2 & ");"
'Debug.Print "Insert " & sSQL
CurrentDb.Execute sSQL, dbFailOnError
答案 0 :(得分:0)
也许这会有所帮助?:
sSQL = "INSERT INTO tblComponents ([Machine Subsystem ID], [NewComponents], [MO_TAG], [Components_Detail])" _
& " VALUES (" & nRid & ", " & nEid & ", '" & nEid1 & "', '" & nEid2 & "');"
我添加了一些''字符串在值括号中的位置。
并且:
[机器子系统ID]
这不应该只是像Machine_Subsystem_ID这样的单词吗?