繁体   English   中英

连续形式的 MS Access VBA 代码在子表单中不起作用

[英]MS Access VBA code in continuous form not working while a subform

下午好,

我遇到了一些代码的问题。 基本上我有一个附加到问答表的子表单。

子表单显示问题,按钮显示答案。

当我直接打开表单时,这很有效,但它不能作为子工作。

这是原始代码:

Set r = Forms![FAQs_Questions].RecordsetClone 'Clone the recordset
r.Bookmark = Forms![FAQs_Questions].Bookmark 'Navigate to the active record
MyAnswer = r!Answer.Value

但是当它是一个子表单时,我收到一条错误消息,上面写着“......找不到引用的表单'FAQs_Questions'。”

所以我尝试了很多东西,我先参考主页,下面是我所有的尝试,每一个都失败了。

Dim r As DAO.Recordset
Set r = Forms![FAQs]![FAQs_Questions].RecordsetClone 'Clone the recordset
r.Bookmark = Forms![FAQs_Questions].Bookmark 'Navigate to the active record
MyAnswer = r!Answer.Value


Dim r As DAO.Recordset
Set r = FAQs.FAQs_Questions.Form.RecordsetClone 'Clone the recordset
r.Bookmark = FAQs.FAQs_Questions.Form.Bookmark 'Navigate to the active record
MyAnswer = r!Answer.Value


Dim r As DAO.Recordset
Set r = FAQs_Questions.Form.RecordsetClone 'Clone the recordset
r.Bookmark = FAQs_Questions.Form.Bookmark 'Navigate to the active record
MyAnswer = r!Answer.Value

Dim r As DAO.Recordset
Set r = Forms!FAQs_Questions.Form.RecordsetClone 'Clone the recordset
r.Bookmark = Forms!FAQs_Questions.Form.Bookmark 'Navigate to the active record
MyAnswer = r!Answer.Value


Dim r As DAO.Recordset
Set r = Forms!FAQs_Questions.Form.FAQs_Questions.RecordsetClone 'Clone the recordset
r.Bookmark = Forms!FAQs_Questions.Form.FAQs_Questions.Bookmark 'Navigate to the active record
MyAnswer = r!Answer.Value

我不知所措。 谁能指出我正确的方向?

谢谢!

由于您的 VBA 是子表单按钮后面的代码,因此您可以通过Me (当前表单;包含代码的表单)引用RecordsetCloneBookmark来简化此操作。

Dim r As DAO.Recordset
Set r = Me.RecordsetClone 'Clone the recordset
r.Bookmark = Me.Bookmark 'Navigate to the active record
MyAnswer = r!Answer.Value

无论Me表单是作为子表单运行还是直接作为顶级表单打开,这种方法都应该有效。

但是,如果您不是绝对需要 go RecordsetCloneBookmark路由,只需直接从表单记录集的当前行检索Answer.Value

MyAnswer = Me.Recordset!Answer.Value

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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