在 Access 2007 中的多个级联下拉框中填充数据
我被分配的任务是在 MS Access 2007 中设计一个临时客户跟踪系统(天哪!)。表和关系均已成功设置。但是我在尝试为一个表设计数据输入表单时遇到了一个小问题......首先是一些解释。
该屏幕包含 3 个下拉框(除了其他字段)。
第一个下拉列表
第一个下拉列表(cboMarket)代表市场,允许用户在两个选项之间进行选择:
- 国内
- 国际
由于第一个下拉列表仅包含 2 个项目,我没有费心为它做一张桌子。我将它们添加为预定义的列表项。
第二个下拉列表
一旦用户在该下拉列表中做出选择,第二个下拉列表(cboLeadCategory) 将加载潜在客户类别列表,即展会和展会。展览、代理、新闻广告、在线广告等。这两个市场使用不同的主导类别。因此,该框依赖于第一个框。
第二个组合的绑定表的结构,名为 Lead_Cateogries 为:
ID Autonumber
Lead_Type TEXT <- actually a list that takes up Domestic or International
Lead_Category_Name TEXT
第三个下拉列表
并且基于第二个组合中的类别选择,第三个 (cboLeadSource ) 应该显示一组属于特定类别的预定义潜在客户来源。
表名为 Lead_Sources ,结构为:
ID Autonumber
Lead_Category NUMBER <- related to ID of Lead Categories table
Lead_Source TEXT
当我在第一个下拉列表中进行选择时,组合的 AfterUpdate 事件被调用,该事件指示第二个下拉列表加载内容:
Private Sub cboMarket_AfterUpdate()
Me![cboLead_Category].Requery
End Sub
第二个组合的行源包含查询:
SELECT Lead_Categories.ID, Lead_Categories.Lead_Category_Name
FROM Lead_Categories
WHERE Lead_Categories.Lead_Type=[cboMarket]
ORDER BY Lead_Categories.Lead_Category_Name;
第二个组合的AfterUpdate事件是:
Private Sub cboLeadCategory_AfterUpdate()
Me![cboLeadSource].Requery
End Sub
第三个组合的行源包含:
SELECT Leads_Sources.ID, Leads_Sources.Lead_Source
FROM Leads_Sources
WHERE [Lead_Sources].[Lead_Category]=[Lead_Categories].[ID]
ORDER BY Leads_Sources.Lead_Source;
问题
当我从 cboMarket 选择市场类型时,第二个组合 cboLeadCategory 会顺利加载适当的类别。
但是,当我从中选择特定类别时,会显示一个模式对话框,要求我输入参数,而不是加载潜在客户来源名称的第三个组合。
替代文本 http://img163.imageshack.us/img163/184/enterparamprompt.png< /a>
当我在此提示中输入任何内容(有效或无效数据)时,我会收到另一个提示:
替代文本 http://img52.imageshack.us/img52/8065/enterparamprompt2.png
为什么会发生这种情况?为什么第三个框没有根据需要加载源名称。任何人都可以阐明我哪里出错了吗?
谢谢, m^e
================================================= ====
更新
我在第三个组合的查询中发现了一个故障。它与第二个组合的值不匹配。我修复了它,现在查询是:
SELECT Leads_Sources.ID, Leads_Sources.Lead_Source
FROM Leads_Sources
WHERE (((Leads_Sources.Lead_Category)=[cboLead_Category]))
ORDER BY Leads_Sources.Lead_Source;
那些讨厌的 Enter Param 提示消失了!!!然而,第三个组合仍然顽固地拒绝加载任何值。有什么想法吗?
I've been assigned the task to design a temporary customer tracking system in MS Access 2007 (sheeeesh!). The tables and relationships have all been setup successfully. But I'm running into a minor problem while trying to design the data entry form for one table... Here's a bit of explanation first.
The screen contains 3 dropdown boxes (apart from other fields).
1st dropdown
The first dropdown (cboMarket) represents the Market lets users select between 2 options:
- Domestic
- International
Since the first dropdown contains only 2 items I didn't bother making a table for it. I added them as pre-defined list items.
2nd dropdown
Once the user makes a selection in this one, the second dropdown (cboLeadCategory) loads up a list of Lead Categories, namely, Fairs & Exhibitions, Agents, Press Ads, Online Ads etc. Different sets of lead categories are utilized for the 2 markets. Hence this box is dependent on the 1st one.
Structure of the bound table, named Lead_Cateogries for the 2nd combo is:
ID Autonumber
Lead_Type TEXT <- actually a list that takes up Domestic or International
Lead_Category_Name TEXT
3rd dropdown
And based on the choice of category in the 2nd one, the third one (cboLeadSource) is supposed to display a pre-defined set of lead sources belonging to the particular category.
Table is named Lead_Sources and the structure is:
ID Autonumber
Lead_Category NUMBER <- related to ID of Lead Categories table
Lead_Source TEXT
When I make the selection in the 1st dropdown, the AfterUpdate event of the combo is called, which instructs the 2nd dropdown to load contents:
Private Sub cboMarket_AfterUpdate()
Me![cboLead_Category].Requery
End Sub
The Row Source of the 2nd combo contains a query:
SELECT Lead_Categories.ID, Lead_Categories.Lead_Category_Name
FROM Lead_Categories
WHERE Lead_Categories.Lead_Type=[cboMarket]
ORDER BY Lead_Categories.Lead_Category_Name;
The AfterUpdate event of 2nd combo is:
Private Sub cboLeadCategory_AfterUpdate()
Me![cboLeadSource].Requery
End Sub
The Row Source of 3rd combo contains:
SELECT Leads_Sources.ID, Leads_Sources.Lead_Source
FROM Leads_Sources
WHERE [Lead_Sources].[Lead_Category]=[Lead_Categories].[ID]
ORDER BY Leads_Sources.Lead_Source;
Problem
When I select Market type from cboMarket, the 2nd combo cboLeadCategory loads up the appropriate Categories without a hitch.
But when I select a particular Category from it, instead of the 3rd combo loading the lead source names, a modal dialog is displayed asking me to Enter a Parameter.
alt text http://img163.imageshack.us/img163/184/enterparamprompt.png
When I enter anything into this prompt (valid or invalid data), I get yet another prompt:
alt text http://img52.imageshack.us/img52/8065/enterparamprompt2.png
Why is this happening? Why isn't the 3rd box loading the source names as desired. Can any one please shed some light on where I am going wrong?
Thanks,
m^e
===================================================
UPDATE
I found a glitch in the query for the 3rd combo.. It wasn't matching up with the value of the second combo. I fixed it and now the query stands at:
SELECT Leads_Sources.ID, Leads_Sources.Lead_Source
FROM Leads_Sources
WHERE (((Leads_Sources.Lead_Category)=[cboLead_Category]))
ORDER BY Leads_Sources.Lead_Source;
Those nasty Enter Param prompts are GONE!!! However, the 3rd combo still stubbornly refuses to load any values. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没关系。找到了修复方法。第二个组合的 BoundColumn 属性未设置为正确的列。因此,其中的选择值不正确,第三个组合无法正确引用链接表(具有正确的索引)。
工作完成:)
感谢所有花时间检查该问题的人。
Never mind. Found the fix. The BoundColumn property of the second combo wasn't set to the correct column. Hence the selection values in it were incorrect and the 3rd combo wasn't able to refer to the linked table properly (with the correct index).
Job done :)
Thanks to all who may have taken time out to review the problem.