在MS Access中设置焦点

问题描述:

我正在从Qdefs创建一个记录集,然后以表格形式显示记录.

I am creating a recordset from a Qdefs and then displaying the records in a form.

当我过滤值时,焦点将移到第一条记录.但是,我希望焦点指向过滤之前焦点所在的同一记录.

When I filter the values, focus is going to the first record. But, I want the focus to point to the same record that was in focus before filtering.

这是在过滤前后根据现有的查询定义创建记录集的方式

This is how am creating a recordset from an existing querydefs before and after filtering

db.QueryDefs("Query_vinod").Sql = filter
Set rs_Filter_Rowsource = db.OpenRecordset("Abfr_SSCI_Check_Findings_List")

我认为您可以通过使用书签来做到这一点.设置一个RecordsetClone,然后使用FindFirst方法找到您的活动记录.我有一些示例代码需要进行一些修改以适合您的确切变量:

I think you can do this by using a bookmark. Set up a RecordsetClone and then find your active record by using the FindFirst method. I have some sample code that will need to be modified a little to fit your exact variables:

Dim Rs As Recordset
Dim Test As Integer
Dim varBookmark As Variant

DoCmd.OpenForm "Contracts"


Set Rs = Forms!Contracts.RecordsetClone

    Rs.FindFirst ("[ID] = '" & Me![ID] & "'")

varBookmark = Rs.Bookmark
Forms!Contracts.Form.Bookmark = varBookmark

If Rs.NoMatch Then
  MsgBox "That does not exist in this database."
Else
End If