Access 2007中表单参数记录源 [英] Access 2007 forms with parameterized RecordSource

查看:142
本文介绍了Access 2007中表单参数记录源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我敢肯定有一个简单的解决办法,但它似乎逃避我。

I'm sure there's a simple solution to this, but it seems to elude me.

所以,我有一个的记录源形式SELECT * FROM表1 WHERE ID = @ ID] 。 (是的,我知道 SELECT * 是邪恶的,它只是一个例子)。 显然,这种形式的默认行为是在打开时,一个输入对话框会提示[@id]值。但我想要做的就是从VBA调用这个形式,而不必输入对话框弹出,继续前进,告诉窗体[@id]是,这样​​的对话从来没有弹出,和窗体打开,就像[@id]其中取代在查询的值。我已经试过以下至今...

So I have a form with a RecordSource of SELECT * FROM Table1 WHERE id=[@id]. (Yes, I know SELECT * is evil; it's just an example). Obviously the default behavior of this form is that upon opening, an input dialog will prompt for the "[@id]" value. But what I would like to do is call this form from VBA and instead of having the input dialog pop up, go ahead and tell the form what [@id] is, so the dialog never pops up, and the form opens just as if [@id] where replaced by a value in the query. I've tried the following so far...

Form_MyForm.RecordSource = String.Replace(Form_Form1.RecordSource, "[@id]", 1)
DoCmd.OpenForm "MyForm"

...和...

...and...

Form_MyForm.txtId.Value = 1
DoCmd.OpenForm "MyForm"

...和...

...and...

DoCmd.OpenForm "MyForm", acNormal, , "[@id]=" & 1

...但他们都不似乎收到预期的效果。我该怎么做呢?

...but none of them seem to have the desired effect. How do i do this?

由于时间提前。

推荐答案

看看它更容易从查询中删除WHERE子句:

See if it's easier to drop the WHERE clause from your query:

SELECT * FROM Table1;

然后,使用的OpenForm可选WhereCondition参数来指明你想要的ID值:

Then use the optional WhereCondition parameter with Openform to indicate which id value you want:

DoCmd.OpenForm "MyForm", WhereCondition:="id = 1"

这篇关于Access 2007中表单参数记录源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆