我想将当前可见表上的可见选定行移动到表的最后一行,以便可以手动填写字段以创建新记录。但是我找不到VBA将Selection(选定的行)移动到打开表的最后一行。我的代码如下所示,但是它无法实现我想要的功能,因此在网上找不到任何解释或示例。
如果我有表中最后一行的索引(.RecordCount从某处开始?),以及将可见光标设置到该行的某种语法(也许records(index).Selected = true
是类似的东西?),我就可以实现我的目标。谢谢。
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
你可以这样做:
strObjName = "myTable"
DoCmd.OpenTable strObjName
' Go to the new record at the bottom
DoCmd.GoToRecord acActiveDataObject, strObjName, acNewRec
' This would go to the last record
' DoCmd.GoToRecord acActiveDataObject, strObjName, acLast
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句