根据另一个字段的值过滤下拉列表 - 请使用语法帮助 [英] filter drop down list based on the value of another field - pls help with syntax

查看:60
本文介绍了根据另一个字段的值过滤下拉列表 - 请使用语法帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我已经找到了这个问题的答案,但是我无法将我正在阅读的内容转移到我的数据库中。我不太了解所需的语言,但能够按照你的指示让我的数据库按照我的意愿行事!


我想过滤一个下拉列表基于另一个字段的输入 - 这也是一个查找字段。有一个学校的主表,我还有两个表 - 一个用于区域,另一个用于列出每个区域的网络。所以:


tblRegions有2个字段:ID和Region;

tblNetworks有3个字段ID,Region和Network。


在学校表格中,当我进入某个地区时,我希望网络下拉列表只给我那些属于该地区的网络。


我已输入行源中的以下内容,但它不起作用 - 有人可以帮我修复它吗:


SELECT [tblNetworks]。[网络] FROM tblNetworks WHERE tblNetworks.Region =表格[Form1上] [区域];!


(表单仍然称为form1,因为我正在查看是否可以使其工作)。


提前致谢,


Marc



I have had a search for the answer to this question, but I can''t transfer what I am reading to my database. I don''t know enough about the language required, but have been able to get my database to do what I want by following your instructions!

I want to filter a drop down list based on the entry of another field - which is also a lookup field. There is a master table of schools, and I have two more tables - one for regions, and then another which lists the networks in each region. So:

tblRegions has 2 fields: ID and Region;
tblNetworks has 3 fields ID, Region and Network.

In a form for schools, when I have entered a region, I want the Network drop down list to give me only those networks that belong in that region.

I have entered the following in the Row Source, but it isn''t working - can someone please help me fix it:

SELECT [tblNetworks].[Network] FROM tblNetworks WHERE tblNetworks.Region=Forms![Form1]![Region];

(the form is still called form1 because I am in the process of seeing if I can make this work).

Thanks in advance,

Marc

推荐答案

我明白你想做什么只是不清楚你是怎么做的并且都不清楚发生了什么或者没有发生。


当我阅读你的帖子时,我会想到这一点。

当你使用一个组合时像这样的盒子经常发生,当你在表单上做出更改时,它的内容不会自动刷新。

我想你可能需要找到一种方法来强制组合框通过VBA进行重新查询,每次你对记录进行更改。


如果你可以提供一些关于你如何构建表单和组合框的更多细节。
I understand what you want to do its just not clear how you are are trying to do it and neither is it clear what is happening or not happening.

Here is what comes to my mind when I read your post.
When you use a combo box like that it often happens that its contents don''t automaticaly refresh as you make changes on the form.
I think you might need to find a way to force the combobox to do a requery via VBA, each time you make a change to the record.

If you can provide a bit more detail on how you have constructed the form and the combo box.


我只是根据我的想法将某些东西扔在一起。


我有一种形式的观点单身M"绑定到学校的桌子

我有一个组合框,从区域表中选择并将ID保存到学校表区域字段。

我有另一个组合框它从网络表中选择一个像你一样的where子句,并将ID保存到学校表网络字段中。


现在可以使网络组合框重新查询。


在区域的onchange事件中combo把这段代码
I just threw something together according to what I think you might be doing.

I have a form of view "single form" bound to the schools table
I have a combo box on it selecting from the regions table and saving the ID into the school tables region field.
I have another combo box on it selecting from the networks table with a where clause like you have, and saving the ID into the school tables network field.

Now the bit to make the network combobox requery.

In the onchange event for the "regions" combo put this code
展开 | 选择 < span class =codeDivider> | Wrap | 行号


首先是Delerna - 为不尽快回复而道歉。我感谢您花时间回答我的问题,然后我没有回复你。我开始回复,但其他事情妨碍了我试图弄清楚你的答案。


所以我终于回来了又去了。


我的表单包含名为:School,Region和Network的字段。 region字段是一个查找tblRegions表的组合框;网络字段有一个组合框,可以查找tblNetworks表,该表还包含每个网络的区域。


该表单名为frmSchools。它基于tblSchools,唯一的关系是组合框的查找表。


在Rowsource for Networks中我输入了以下内容(根据我原来的帖子)当我选择一个区域时,它会将网络过滤到只与那个区域相匹配的区域。


SELECT [tblNetworks] .Network FROM tblNetworks WHERE tblNetworks.Region = Forms![FrmSchools] ![区域];


然而,当我进入formview时,下拉框中没有任何内容。


我还将以下代码放入即使根据您的建议,区域也在变化:


私有子Region_Change()


Network.Requery


End Sub


最初我按字面意思粘贴你的代码,并且遇到运行时错误,我的字段叫做Network,所以我把它改成了上面的代码。我认为代码是可以的,但我没有解决我的问题,因为我在网络的行源中写了什么。


这是否为您提供了更好的信息来理解如何我做了什么?我是一名自学成才的Access用户,并且根本无法理解表达式和代码。


感谢您的帮助,


Marcella
Firstly Delerna - huge apologies for not replying sooner. I appreciate that you took time to answer my question, and then I did not reply to you. I started to reply but other things got in the way of my trying to make sense of your answer.

SO I have finally come back and had another go.

My form has fields named: School, Region and Network. The region field is a combo box that looks up the tblRegions table; the network field has a combo box that looks up the tblNetworks table which also holds the region for each network.

The form is called frmSchools. It is based on tblSchools, and the only relationships are the lookup tables for the comboboxes.

In the Rowsource for Networks I have typed the following (as per my original post) in the hope that when I select a region, it will filter the networks to only those that match the region.

SELECT [tblNetworks].Network FROM tblNetworks WHERE tblNetworks.Region=Forms![FrmSchools]![Region];

However, when I then go into formview, there is nothing in the drop down box.

I also put the following code into the Region On Change even as per your advice:

Private Sub Region_Change()

Network.Requery

End Sub

Initially I pasted your code in literally, and got runtime error, my field is called Network, so I changed it to the above. I think that code is okay, but I haven''t solved my problem because of what I have written in the rowsource for Network.

Does that provide you with better information to understand how I have set things up? I am a self taught Access user, and don''t have my head around expressions and code very well at all.

Thanks for your help,

Marcella


这篇关于根据另一个字段的值过滤下拉列表 - 请使用语法帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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