MS Access 2007 OpenForm 方法,无法让 where 子句产生正确的结果
我无法获取 OpenForm 方法来打开加载了正确记录的表单。我将在这里尽力提供详细信息:
“源”表单基于表 A,并且是只读的。源表单上的按钮用于打开“目标”表单,该表单用于编辑记录(也来自表 A)。
我尝试使用向导创建基于主键相等打开表单的按钮。向导的结果是,无论源表单上下文中的记录是什么,目标表单都只会加载表 A 中的第一条记录。
我尝试使用具有以下变体的过程:
Dim frm As String, whr As String
frm = "Target Form"
whr = "Forms![Source Form]!ID = Forms![Target Form]!ID"
'whr = "[ID] = [ID]"
'whr = "[ID] = Forms![Target Form]!ID"
DoCmd.OpenForm frm, acNormal, , whr, , , 1
我可以仅获取要在目标表单中加载的第一条记录,也可以获取要在目标表单中加载的新记录。但我无法获取源表单的加载记录来确定加载到目标表单中的记录。
感谢您的帮助
I can not get the OpenForm method to open a form with the correct record loaded. I'm going to do my best here to provide the details:
The 'source' form is based off Table A, and it is read-only. A button on the source form is being used to open a 'target' form that is used for editing records, also from Table A.
I have tried using the wizard to create the button that opens the form based on primary key equality. The result from the wizard is that no matter what record is in context on the source form, only the first record in Table A is ever loaded by the target form.
I have tried using a procedure with the following variations:
Dim frm As String, whr As String
frm = "Target Form"
whr = "Forms![Source Form]!ID = Forms![Target Form]!ID"
'whr = "[ID] = [ID]"
'whr = "[ID] = Forms![Target Form]!ID"
DoCmd.OpenForm frm, acNormal, , whr, , , 1
I could either get only the first record to load in the target form or get a new record to load in the target form. But I can not get the source form's loaded record to determine the record loaded into the target form.
Thanks for any help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想你已经很接近了。您希望WhereCondition 与目标表单记录源查询的WHERE 子句相同,但不包含WHERE 一词。
我打算将 Me.ID 作为名称为 ID 的控件的值,并绑定到源表单当前记录中的字段。 Me 是“这种形式”的简写。它有用的原因之一是,如果您稍后决定为表单指定不同的名称,则无需修改代码。
我添加了 Debug.Print 语句,以便您可以切换到立即窗口 (Ctrl+g),并复制 whr 字符串,然后将其粘贴到基于目标表单使用的相同记录源的新查询中。如果您在目标表单打开时仍然无法显示正确的记录,这可能会有所帮助。
您的版本还包括 1 作为 OpenArgs 到 OpenForm。没看懂你怎么用的,所以就放弃了。如果目标表单包含使用 OpenArgs 执行某些操作的事件过程,请确保它不会覆盖您的WhereCondition。
I think you got close. You want the WhereCondition to be the same as a WHERE clause for a query of Target Form's record source, but without the word WHERE.
I intended Me.ID as the value of a control whose name is ID and is bound to a field in the current record of Source Form. Me is shorthand for "this form". One reason it's useful is because you wouldn't have to revise your code if you later decide to give the form a different name.
I added the Debug.Print statement so you can switch to the Immediate Window (Ctrl+g), and copy the whr string, then paste it into a new query based on the same record source which Target Form uses. That could be helpful in case you still don't get the correct record displayed when Target Form opens.
Your version also included 1 as OpenArgs to OpenForm. I didn't see how you were using that, so left it off. If Target Form includes an event procedure which does something with OpenArgs, make sure it doesn't override your WhereCondition.