我选择DoCmd.RunSQL
了一个特定的功能,而不是CurrentDb.Execute
因为我想利用 Access 的内置警告来让用户选择回滚查询。但是,当我今天运行它时,我注意到它不再显示警告。当我编写程序时,我几乎可以肯定它确实如此。
我已经尝试过明确设置DoCmd.SetWarnings True
,即使没有理由一开始就SetWarnings
应该关闭,但这并不能解决问题。有谁知道问题可能是什么?
我的代码在下面(为了节省空间,稍微编辑了一下)。作为参考,这是上下文菜单上的一项功能,它记录当前记录的字段值,并将记录集中的所有记录更新为相同的值。它生成的查询是正确的,并且可以正确执行——但它不会首先显示警告消息。
Public Function FillFoundRecords()
On Error GoTo ErrHandler
Dim controlField As String, idName As String, _
commandText As String, whereClause As String
'First save the current record
DoCmd.RunCommand acCmdSaveRecord
controlField = Screen.ActiveControl.ControlSource
With Screen.ActiveForm
'Check for any where clauses or filters on the active form
whereClause = GetWhereClause(.RecordSource)
'Build the UPDATE command. This uses a few custom functions and properties,
'but it's not the problem -- it always produces the correct query statement.
commandText = _
"UPDATE " & .BaseTable & _
" SET [" & controlField & "] = " & ActiveControlFilter & _
" WHERE " & whereClause
DoCmd.SetWarnings True
DoCmd.RunSQL commandText
.Refresh
End With
ExitHandler:
On Error Resume Next 'Ignore further errors
Exit Function
ErrHandler:
If Err.Number = 2501 Then 'RunSQL command was cancelled; ignore this
Resume ExitHandler
Else
ErrorHandle
Resume ExitHandler
End If
End Function