我想将当前可见表上的可见选定行移动到表的最后一行,以便可以手动填写字段以创建新记录。但是我找不到VBA将Selection(选定的行)移动到打开表的最后一行。我的代码如下所示,但是它无法执行我想要的操作,因此在网上找不到任何解释或示例。
If I had the index of the last row in the table (.RecordCount from somewhere?) and some syntax for setting the visible cursor to that row (maybe records(index).Selected = true
or something like that?), I could accomplish my goal. Thank you.
Sub TableLastRowMove()
Dim tbl As AccessObject, tblname As String
tblname = Application.CurrentObjectName
' get a handle to the currently open table and print its name
Set tbl = Application.CurrentData.AllTables(tblname)
Debug.Print tbl.name
' I want to move the visible selected record to the end of the table
' I think I need something like
' set selection = ActiveTable.LastRow
' But that is not available in Access
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("SELECT * FROM " & tbl.name)
If Not rs.EOF Then
rs.MoveLast
' I want to say
' rs.currentRecord.Selected = true
' but that is not available either
End If
rs.Close
Set rs = Nothing
End Sub
你可以这样做: