因此,我创建了一个表单(只有具有开发人员安全级别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“是尝试的正确方法
答案 0 :(得分:2)
您可以调用此代码-此处包含在 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
。