使用 DAO 从报表中转到子表单上的特定记录

From within a Report go to a spesific record on subform using DAO

我希望用户单击报表中的超链接,然后导航到位于子表单中的特定记录

This 线程通过使用 Docmd.openform 并传递 OpenArg 参数非常有效,但是如果您想要更多功能或希望传递多个参数怎么办?

我在使用 DAO 的报告超链接字段中获得了以下代码,但我无法正常工作:

    Private Sub Text209_Click()
        ''open specific journal entry
        DoCmd.OpenForm "BatchJ Form"
        Forms![BatchJ Form]![Journal Form].SetFocus ''set focus to subform journal

        ''now find the journal entry
        Dim dbs As DAO.Database
        Dim rst As DAO.Recordset

        'Get the database and Recordset
        Set dbs = CurrentDb
        Set rst = dbs.OpenRecordset("Journal Tbl", dbOpenDynaset)

        'Search for the first matching record
        rst.FindFirst "[Journal ID] = " & CLng(Me.CrJournal)
        Forms![BatchJ Form]![Journal Form].Recordset.Bookmark = rst.Bookmark ''this line gives me an error: "Object doesn't support this object or method"

        ''cleanup
        rst.Close
        Set rst = Nothing
        Set dbs = Nothing
    End Sub

您可能正在寻找这样的东西:

Private Sub Text209_Click()
    Dim rst As DAO.Recordset

    ''open specific journal entry
    DoCmd.OpenForm "BatchJ Form"
    Forms![BatchJ Form]![Journal Form].SetFocus ''set focus to subform journal

    ''now find the journal entry
    Set rst = Forms![BatchJ Form]![Journal Form].Form.RecordsetClone
    'Search for the first matching record
    rst.FindFirst "[Journal ID] = " & CLng(Me.CrJournal)
    Forms![BatchJ Form]![Journal Form].Form.Bookmark = rst.Bookmark

    ''cleanup
    rst.Close
    Set rst = Nothing
End Sub