级联列表问题 [英] Cascading List Problem

查看:64
本文介绍了级联列表问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

祝福所有人。我知道级联列表是一个常见的问题,事实上我在这里的初始帖子是请求我自己的帮助,但后来我找到了正确的代码。话虽这么说,我有一个新的挑战,我不知道该怎么办。这是我的情况:


我目前有2个组合框(cboBuilding,cboRoom),并且正确级联。这很好,但现在我想能够为所选的房间拉出RoomDescription(基本上自动填充表格上的字段,如果可能的话,它是不可编辑的)。我不确定如何去做这件事。


以下是我的两张桌子的基本布局和我所做的:

tblBuilding

[BuildingID] - 建筑表的主键(自动编号)

[BuildingName] - 建筑物名称

tblRoom

[RoomPK] - 房间表的主键(自动编号)

[RoomNumber] - 特定房间的房间号码

[RoomDescription] - 房间描述

[BuildingID] - FK到建筑表;确定特定于哪个建筑物房间


私有子建筑物_更新后()


''选择建筑物时,相应的房间列表将<
''显示在CboRoom的下拉列表中


1.和我在一起![房间]

2.如果是IsNull(我!建筑物)然后

3. .RowSource =""

4.否则

5. .RowSource =" SELECT [ RoomNumber] &安培; _

6." FROM tblRoom" &安培; _

7.WHERE [BuildingID] =" &安培;我!建筑

8.

9.结束如果

10.致电.Requery

11.结束

12.结束Sub


**我对代码的外观表示歉意。我写的它间隔得很好而且整洁但是当我发布它不包括我的空间时,任何有关如何修复的帮助都会对以后的帖子表示赞赏**


所以查询以上工作可以自动填充我的房间列表,但我不确定如何将房间描述放到表格上。首先,表单的来源是一个单独的表,对于房间没有任何关系(具体而言),我之前使用过代码(上图)。我设法得到一个房间描述字段上的字段,虽然它抱怨控制源(理所当然)因为此表单的主要数据源不包括房间表数据。


我确定我所有的需要的是创建一个查询,该查询将基于用户的前两个选项(即选择的建筑物和特定房间)拉入字段的房间描述。我知道我想要完成什么我只是不确定 如何 来实现它。我要建立另一个活动吗?如果是这样,哪一个?再次更新后?


非常感谢任何帮助!如果您需要更多信息,请告诉我们!

Greetings all. I know that cascading lists are a common problem and in truth I my initial post here was to request help with my own, but then I figured out the right code. That being said, I have a new challenge which I''m not sure how to go about. Here is my situation:

I presently have 2 combo boxes (cboBuilding, cboRoom) and which are properly cascading. That''s great, but now I want to be able to pull the RoomDescription for the room that was selected (basically autopopulate a field on the form and have it be uneditable if possible). I am uncertain how to go about doing this.

Here are the basic layouts of my two tables and what I have done:

tblBuilding
[BuildingID] - Primary Key (Autonumber) for Building Table
[BuildingName] - Name of Building

tblRoom
[RoomPK] - Primary Key (Autonumber) for Room Table
[RoomNumber] - Room Number for specific room
[RoomDescription] - Description of the room
[BuildingID] - FK to Building Table; identifies which building specific room is in

Private Sub Building_AfterUpdate()

''When the Building is selected, the appropriate Room list will
''display in the drop down list of CboRoom

1. With Me![Room]
2. If IsNull(Me!Building) Then
3. .RowSource = ""
4. Else
5. .RowSource = "SELECT [RoomNumber] " & _
6. "FROM tblRoom " & _
7. "WHERE [BuildingID]=" & Me!Building
8.
9. End If
10. Call .Requery
11. End With
12. End Sub

** My apologies for how the code looks. I write it spaced out nice and neat but when I post it doesn''t include my spaces, any help with how to fix that is appreciated for future posts **

So the query above works fine to autopopulate my Room list, however I am not certain how to go about getting the Room Description onto the form. For one, the source for the form is a single table which has nothing to do (specifically) for the Room, which I used code to work around previously (above). I''ve managed to get a "Room Description" field onto the form, though it is complaining about the control source (rightfully so) as the primary data source for this form is exclusive of the Room Table data.

I am certain all I need is to create a query which will pull in the room description for the field based on the previous two choices by the user (i.e. the Building and specific Room selected). I know what I want to accomplish, I am just not certain as to the how to make it happen. Do I build another event? If so, which one? After Update again?

Any help is greatly appreciated! If you need more information, please let me know!

推荐答案

假设您希望在名为txtRoomDescription的文本框中显示房间描述:
Assuming you wish to display the Room Description in a Text Box named txtRoomDescription:
展开 | 选择 | Wrap | 行号



假设您希望在名为txtRoomDescription的文本框中显示房间描述:
Assuming you wish to display the Room Description in a Text Box named txtRoomDescription:
展开 | 选择 | Wrap | 行号


好的,我杀了控制源,以便现在将字段视为UNBOUND(呃,不知道为什么没有'''以前发生在我身上......这是早期和周一:-)但我的代码不起作用。我有一个类似你所建议的变体,但我能想到的唯一的地方就是事后。对于ROOM,以便为RoomDescription创建行源。这是错误的(因为它不起作用)或者我做错了什么。这是我的After Event目前的程序:

Okay, I killed the control source so that the field is considered UNBOUND now (duh, not sure why that didn''t occur to me previously ... it''s early and a Monday :-) but my code isn''t working. I had a similar variant of what you had suggested but the only place I can think of putting it is in the "AFTER EVENT" for ROOM in order to create the row source for RoomDescription. Either this is wrong (as it isn''t working) or I''m doing something wrong. Here is my "After Event" procedure at present:

展开 | 选择 | Wrap | 行号


这篇关于级联列表问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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