访问 VBA Insert INTO 错误
Access VBA Insert INTo Error
我有一个名为 lstAvailable 的列表框,我正在尝试将从中选择的值发送到 table。但是我收到一条错误消息,指出 Insert Into 语句中存在语法错误。 Machine Subsystem ID,NewComponents是integer类型,MO_TAG和Components_Detail是text类型
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
也许这会有所帮助?:
sSQL = "INSERT INTO tblComponents ([Machine Subsystem ID], [NewComponents], [MO_TAG], [Components_Detail])" _
& " VALUES (" & nRid & ", " & nEid & ", '" & nEid1 & "', '" & nEid2 & "');"
我在值括号中的字符串处添加了一些 ' '。
并且:
[机器子系统 ID]
这不应该像Machine_Subsystem_ID一样只有一个词吗?
我有一个名为 lstAvailable 的列表框,我正在尝试将从中选择的值发送到 table。但是我收到一条错误消息,指出 Insert Into 语句中存在语法错误。 Machine Subsystem ID,NewComponents是integer类型,MO_TAG和Components_Detail是text类型
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
也许这会有所帮助?:
sSQL = "INSERT INTO tblComponents ([Machine Subsystem ID], [NewComponents], [MO_TAG], [Components_Detail])" _
& " VALUES (" & nRid & ", " & nEid & ", '" & nEid1 & "', '" & nEid2 & "');"
我在值括号中的字符串处添加了一些 ' '。
并且:
[机器子系统 ID]
这不应该像Machine_Subsystem_ID一样只有一个词吗?