我试图通过以下代码了解我的问题所在。
'add data to table
CurrentDb.Execute "INSERT INTO IB Students(Student Name, Gender, IB) " & _
"VALUES (" & Me.Text6 & ",'" & Me.Combo13 & "','" & Me.Text9 & "')"
'refresh data in list on form
stdfrm.Form.Requery
每当我尝试使用add命令时,我得到Runtime Error -3134
并且它说INSERT INTO
语句存在语法错误。
答案 0 :(得分:3)
可能需要用括号括起表的名称,并且必须引用文本值:
'add data to table
sSQL = "INSERT INTO [IB Students] ([Student Name], Gender, IB) " & _
"VALUES ('" & Me.Text6 & "','" & Me.Combo13 & "','" & Me.Text9 & "')"
'print SQL for debug
Debug.print sSQL
'Run query
CurrentDb.Execute sSQL
'refresh data in list on form
stdfrm.Form.Requery
注意:如果Me.Text6
(和其他人)未绑定到数据源,则必须将其用作Me.Text6.Value
编辑:在运行查询之前检查长度可能是一个好主意
答案 1 :(得分:0)
当我打开即时窗口时显示
INSERT INTO [IB Students] (Student Name, Gender, IB) VALUES (Micheal,'Male','2')
INSERT INTO [IB Students] (Student Name, Gender, IB) VALUES (John,'Male','1')
INSERT INTO [IB Students] ([Student Name], Gender, IB) VALUES (,'','')
INSERT INTO [IB Students] ([Student Name], Gender, IB) VALUES (,'','')