所以我创建了一个表单(只有具有开发人员安全级别ID的人可访问/加载),允许我将SQL语句输入到未绑定的文本框并执行。
如果语句失败,它会在表单中填充一个带有失败错误/描述的连续子表单,但是在快速me.refresh之后它会跳转到第一条记录,无论我尝试什么,我都无法跳转到最后一条记录。
我试过了:
Me.sub_ConsoleRTN.Form.ConsoleRTN.MoveLast
并且:
Me.sub_ConsoleRTN.Form.ConsoleRTN.SetFocus
DoCmd.RunCommand accmdRecordsGoToLast
并且它们没有错误地运行但是没有显示最后的记录
这是完整的代码:
Private Sub ExecuteSQL_Click()
On Error GoTo ErrorHandler
Dim strSQL As String
Dim myCI As String
myCI = txt_sqlConsole.Value
If myCI = "" Then
strSQL = "INSERT INTO tbl_ADM_Console " & "(ErrNumber,ErrDescription) VALUES" & "(101, 'Cannot exectute blank statement')"
CurrentDb.Execute strSQL, dbFailOnError
Me.txt_actionconf.Value = "Action cancelled - compile error"
Me.Refresh
Me.sub_ConsoleRTN.Form.ConsoleRTN.SetFocus
DoCmd.RunCommand acCmdRecordsGoToLast
Else
strSQL = myCI
CurrentDb.Execute strSQL, dbFailOnError
Me.txt_actionconf.Value = "Action completed"
Me.Refresh
DoCmd.GoToRecord , , acLast
End If
Exit_ExecuteSQL: ' Label to resume after error.
Exit Sub ' Exit before error handler.
ErrorHandler: ' Label to jump to on error.
Call logConsoleErrors(Err.Number, Err.Description, "Console()")
Me.txt_actionconf.Value = "Action cancelled - compile error"
Me.Refresh
Resume Exit_ExecuteSQL
End Sub
一如既往,我可能会遗漏一些非常简单的东西,但互联网上的消息来源暗示“Me.sub_ConsoleRTN.Form.ConsoleRTN.SetFocus DoCmd.RunCommand accmdRecordsGoToLast”是正确的尝试方法
您可以调用此代码 - 此处包含在OnLoad事件中:
Private Sub Form_Load()
Dim rs As DAO.Recordset
Set rs = Me.RecordsetClone
If rs.RecordCount > 0 Then
rs.MoveLast
Me.Bookmark = rs.Bookmark
End If
rs.Close
End Sub
如果你的表单绑定到tbl_ADM_Console,你可以跳过所有代码,只需在AddNew
上使用RecordsetClone
。