的MS Access:如何提供参数基于查询的子控件控件、参数、MS、Access

2023-09-08 11:17:26 作者:荣辱兴亡盛衰

鉴于以下设置,你怎么提供参数查询:

Given the following setup, how do you supply parameters to the query?:

在形式上包含SubformA。 SubformA使用QueryA,已保存的查询,为SourceObject。 QueryA使用参数声明 在形式上包含提供参数QueryA控制。

如果形式上的控制具有相同的名称作为QueryA的参数,这通常工作。唯一的例外是当窗体加载,此时访问提示输入QueryA的参数用户。我想解决这个问题留在设计视图SubformA的SourceObject空白,并确定在形式上的Form_Load事件的SourceObject。我设置了备考的控件的值,然后设置SubformA的SourceObject。但是,Access仍提示输入参数。我的下一个想法是让一个引用QueryA作为的QueryDef并定义的QueryDef的参数,但似乎没有一种方法来分配的QueryDef为SubformA的SourceObject。如何获得不提示输入参数,用户在窗体加载?

If FormA's Controls have the same name as QueryA's parameters, this generally works. The exception is when the form loads, at which time Access prompts the user for QueryA's parameters. I am trying to get around this by leaving SubformA's SourceObject blank in Design View and defining the SourceObject in FormA's Form_Load event. I am setting the values of FormA's controls and then setting SubformA's SourceObject. However, Access is still prompting for the parameters. My next thought was to get a reference to QueryA as a QueryDef and define the QueryDef's parameters, but there doesn't appear to be a way to assign the QueryDef as SubformA's SourceObject. Any thoughts on how to obtain the objective of not prompting the user for the parameters on form load?

推荐答案

你定义的控件的子窗体的记录源参数?我不知道它会工作即使是这样,因为我想子窗体负荷的主要形式面前,他们正在重新查询加载后第二次。

Have you defined the controls as parameters in the Recordsource of the subform? I'm not sure it would work even then, since I think subforms load before the main form, and that they are requeried a second time after loading.

我会建议其子窗体中的一个空的记录源,并设置记录源SQL时应用过滤器。我不定义任何参数,我会用任何引用,从而在记录源SQL控制的。

I'd suggest having an empty recordsource in the subform, and set the Recordsource SQL when you apply the filter. I wouldn't define any parameters and I would use no references to form controls in the Recordsource SQL at all.

如果你是莫名其妙地担心SQL注入,并认为你必须使用的参数,可能你的担心被夸大了,特别是如果没有过滤器控件允许自由文本。

If you are somehow concerned about SQL injection and think you must use parameters, likely your concerns are overblown, particularly if none of the filter controls allow free text.