尝试将值插入Access数据库的操作无效

时间:2016-11-13 19:16:34

标签: sql ms-access access-vba

我在下面有这个代码,当我尝试运行它时,它会在代码的最后一行显示错误消息“无效操作”。所有语法看起来都正确。我究竟做错了什么?

PCycle = PreviousCycle(CurrentCycle(Me.cobMainType.Value), mainType(Me.cobMainType.Value))

SQL = "INSERT INTO tblVehMainType (MainID, PartID, VehTypeID)"
SQL = SQL & " Select " & Me.cobMainType & ", PartID, VehTypeID"
SQL = SQL & " From tblVehMainType "
SQL = SQL & " WHERE vehTypeID = " & Me.cobVehType & " AND MainID = " & PCycle & ";"

Set rst = CurrentDb.OpenRecordset(SQL)

1 个答案:

答案 0 :(得分:2)

INSERT语句不会返回记录集,因此您不应使用.OpenRecordset来运行它。您应该使用.Execute代替。