在子窗体的详细部分上过滤了组合框 [英] Filtered Combo Box on the detailed section of a subform

查看:42
本文介绍了在子窗体的详细部分上过滤了组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好:


我有一个表单(默认视图=单个表单),其中嵌入了一个子表单(默认视图=连续表单)。在表单中,我有三个控件显示分区,工作区域和信用区。子表单显示数据/记录。我的表单和子表单的记录源都是由查询驱动的,这是我通过我创建的另一个表单过滤最终用户将看到的记录的方式。


一切正常很好,但我似乎无法解决以前从未做过的事情。


问题是最终用户可以通过我的子表单添加新记录。我的挑战是,显示的一个字段是什么?产品?在此下拉列表中有很多产品可供选择,但如果列表是按工作区域筛选的,则没有多少产品可供选择。我的产品表的布局如下:


产品:

tblProduct

ProductID =自动编号

ProductsName =文字

WrkRegID =数字(这是我的一对多关系;工作区域可以有很多不同的产品)


有没有在我的子表单上过滤我的产品字段列表以获取新记录的方法?


我试图尝试这样做而无法弄明白。我所做的工作是在我的子表单的标题中,我放在一个组合框中然后在该表单的load事件上写下了以下代码:

Hello:

I have a form (Default view =single form) with a subform (Default view =continuous forms) embedded into it. In the form I have three controls that display the Division, Working Region & Credit Region. The subform displays the data/records. The record source for both my form and subform is driven by a query, which is the way I filter the records that the end user will see via another form I created.

Everything is working fine but I can not seem to figure something out that I have never done before.

The issue is that the end user can add a new record via my subform. My challenge is that one of the fields that is displayed is called ?Product? There are a lot of products to choose from on this drop down list but not as many if the list was filtered by Working Region. The layout of my product table is as follows:

Product:
tblProduct
ProductID = Autonumber
ProductsName = Text
WrkRegID = Number (This is for my one to many relationship; a working region can have many different Products)

Is there a way to filter the list of my product field on my subform for new records?

I was trying to experiment with doing this and can not figure it out. What I did get to work was on the header of my subform I dropped in a combo box and then on the load event of that form wrote the following code:

展开 | 选择 | Wrap | 行号

推荐答案

嗨基思。根据你的说法,似乎组合没有绑定到子表单中的某个字段,因为除非你在从组合中进行选择时调用更新后事件来更新记录,否则它不能

子表单实际上在表单上显示的每一行上重复相同的控件集,如果有的话这些是未绑定的,你会看到每一行都重复相同的值。这使得它看起来像你已经改变了所有记录 - 但正如所提到的,除非有使用After Update事件,它实际上并没有对你的记录做任何事情。


未绑定控件是一个其controlsource为空的 - 一个未绑定到基础表中特定字段的控件。如果要在子表单的详细信息部分中嵌入未绑定的组合框控件,则它位于错误的位置。


问问自己组件要对子窗体做什么,如果要为子窗体中的某个表值提供列表,则需要将其绑定到适当的领域。


顺便说一下,只有在你第一次打开表单时才会触发表单加载事件 - 这是在事件代码中加载条件记录源的正确时机吗?


-Stewart
Hi Keith. From what you say it would appear that the combo is not bound to one of the fields in your subform, as unless you are calling an after-update event to update records when you make a selection from the combo it cannot of itself change multiple records - but it can give the appearance that it is.

A subform actually repeats the same set of controls on each row shown on the form, and if one of those is unbound you see the same value repeated on every row. This makes it look like you have changed all records - but as mentioned unless there is an After Update event in use it has not actually done anything at all to your records.

An unbound control is one whose controlsource is blank - one that is not bound to a specific field in your underlying table. If you are embedding an unbound combo box control in the detail section of your subform it''s in the wrong place.

Ask yourself what you want the combo to do on your subform, and if that is to provide a list for one of the table values in your subform you will need to bind it to the appropriate field.

By the way, the form load event is fired only when you first open the form - is this the right timing for the conditional recordsource loading in your event code?

-Stewart


您好:


让我先回答最后一个问题:


顺便说一下,只有在你第一次打开表单时才会触发表单加载事件 - 这是在事件代码中加载条件记录源的正确时机吗?


一旦最终用户进入表格工作区域,参数不能在其中更改,因此加载事件只会触发一次没有问题。


另一方面,我还不是提前访问者,所以请耐心等待我不完全理解你的回答。


让我看看我是否能更好地解释这个场景:


让我们说我的子窗体显示3条只有3个字段的记录:
Hello:

Let me answer the last question first:

"By the way, the form load event is fired only when you first open the form - is this the right timing for the conditional recordsource loading in your event code?"

Once the end user in on the form the "working region" parameter can not be changed within it, so there is no problem with the load event only firing once.

On another note, I am not yet an advance Access person so please be patient if I don''t entirely understand your response.

Let me see if I can better explain the scenario:

Let''s say my subform is displaying 3 records that only have 3 fields:
展开 | 选择 | Wrap | 行号


Hi Keith。您可以使用组合选择产品字段,该组合与产品字段本身的值绑定。要执行此操作,请删除子窗体上的现有产品字段并将其替换为组合,使用组合向导为产品表中的记录源构建基本查询。这可以使用类似于表单加载事件中的WHERE子句进行调整,以过滤该区域。 DLookup不是必需的。


这个的SQL看起来像:
Hi Keith. You can use a combo for selection of the product field, a combo which is bound to the value of the product field itself. To do this you delete your existing product field on the subform and replace it with a combo, using the combowizard to build the basic query for the recordsource from your product table. This can be tweaked with a WHERE clause similar to the one in your form load event to filter for the region. The DLookup should not be necessary.

The SQL for this will look something like:
展开 | 选择 | 换行 | 行号


这篇关于在子窗体的详细部分上过滤了组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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