【问题标题】:Access 2016: Runtime error 3061 (VBA)Access 2016:运行时错误 3061 (VBA)
【发布时间】:2017-12-01 11:30:02
【问题描述】:

我创建了一个表单来从某个表中删除一条记录。它包含一个字段,用户可以在其中键入他想要删除的记录的 ID(字段名称:“idp”)。单击按钮验证删除。在按钮后面我有以下代码:

Private Sub button12_Click()
Dim dbs As Database, rst As Recordset
Set dbs = CurrentDb
dbs.Execute "DELETE * FROM " _
    & "mytable WHERE ID = Me.idp;"
dbs.Close
DoCmd.Close End Sub

但是,我在尝试使用它时不断收到错误 3061。 (“错误 3061 参数太少。预期为 1”)感谢您的帮助,伙计们。

【问题讨论】:

  • 你能把错误信息和代码包括进来吗?

标签: ms-access vba


【解决方案1】:

你可以这样试试吗:

Private Sub button12_Click()

    Dim dbs As Database, rst As Recordset
    dim strCommand as String

    Set dbs = CurrentDb

    strCommand = "DELETE * FROM " & "mytable WHERE ID = " & Me.idp
    debug.print strCommand 
    dbs.Execute strCommand

    dbs.Close
    DoCmd.Close 

End Sub

我认为您没有将Me.idp 作为参数传递,但它在字符串中。

一般来说,运行后,看一下立即窗口。如果您在 Access 中打开一个新查询,那里的 SQL 应该是可执行的。

【讨论】:

  • 行 dbs.Execute "DELETE * FROM " & "mytable WHERE ID = " & Me.idp;以红色突出显示自身并给出编译错误。 :(
  • @TamásKovács - 再试一次。立即显示的窗口是什么?
  • 现在可以工作了...行尾不需要分号:)
  • @TamásKovács - 是的,我在第二次编辑时忘记了。
  • 应该是Debug.print strCommand,看看实际运行的是什么。但是使用它+1。 How to debug dynamic SQL in VBA
猜你喜欢
  • 1970-01-01
  • 2023-03-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-04-20
  • 1970-01-01
  • 1970-01-01
  • 2018-07-09
相关资源
最近更新 更多