下午好,
我在 VBA 中的 INSERT 语句有问题。每次我尝试通过表单的输入向表中插入新记录时,都会出现错误。
运行时错误“3061”:参数太少。预计2。
这就是它背后的 VBA。
Private Sub Command242_Click()
Dim dbs As Database
' Modify this line to include the path to Northwind
' on your computer.
Set dbs = CurrentDb
'Testing purpose
Me.cbPenalty1 = 0
Me.cbOwnGoal1 = 0
' Create a new record in the tblMatchPlayer table.
' Query saved the player who scored with values in a new row, linked with MatchID & PlayerID.
'Testing purpose MsgBox - DELETE WHEN WORKS!!
MsgBox " INSERT INTO tblMatchPlayer " _
& "(MatchID, PlayerID, SubstituteID, PositionID, Surname, ScoreTime, RedCards, YellowCards, Substitude, Penalty, OwnGoal, Assist) VALUES " _
& "(" & Me.MatchID & ", '', '', '', " & Me.cmScoreName1 & ", " & Me.tbScoreTime1 & ", '', '', '', " & Me.cbPenalty1 & ", " & Me.cbOwnGoal1 & ", " & Me.cmAssist1 & ");", vbOKOnly, "Query Show"
'Actual INSERT
dbs.Execute " INSERT INTO tblMatchPlayer " _
& "(MatchID, PlayerID, SubstituteID, PositionID, Surname, ScoreTime, RedCards, YellowCards, Substitude, Penalty, OwnGoal, Assist) VALUES " _
& "(" & Me.MatchID & ", '', '', '', " & Me.cmScoreName1 & ", " & Me.tbScoreTime1 & ", '', '', '', " & Me.cbPenalty1 & ", " & Me.cbOwnGoal1 & ", " & Me.cmAssist1 & ");"
dbs.Close
End Sub
当 MsgBox 弹出窗口向我显示它将在表中写入的查询时,我得到了这些结果。
插入 tblMatchPlayer(MatchID、PlayerID、substituteID、PositionID、姓氏、ScoreTime、RedCards、YellowCards、Substitude、点球、OwnGoal、Assist)值(29、''、''、''、Grozema、34、''、'' , '', 0, 0, 熊);
我看不出这个插入查询有什么问题。但是 VBA 确实似乎认为他缺少一些参数,但我不知道是什么参数。
我表中的字段是这样的。
- MatchPlayerID - 自动编号
- MatchID - 号码
- PlayerID - 号码
- SubstituteID - 号码
- PositionID - 编号
- 姓氏 - 文字
- ScoreTime - 文本
- 红卡 - 文本
- YellowCards - 文本
- 替代品 - 文字
- 处罚 - 是/否
- 自己的目标 - 是/否
- 辅助 - 文字
你们能帮帮我吗?
亲切的问候,帕特里克