简体   繁体   中英

Setting focus in MS Access

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")

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM