【问题标题】:From within a Report go to a spesific record on subform using DAO使用 DAO 从报告中转到子表单上的特定记录
【发布时间】:2015-10-01 10:12:19
【问题描述】:

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

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

【问题讨论】:

  • 如果我将出现错误的行更改为:“Forms![BatchJ Form]![Journal Form].Form.Recordset.Bookmark = rst.Bookmark”然后我得到这个错误“not a valid书签”

标签: ms-access vba dao


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2015-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-14
    • 1970-01-01
    • 2020-05-08
    • 2022-01-20
    • 2019-01-09
    相关资源
    最近更新 更多