用于组合框和子表单的VB代码 [英] VB Code for Combo Box and subform

查看:66
本文介绍了用于组合框和子表单的VB代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为cmb_category的组合框。然后我有这样的SQL语句:

SELECT Originations_Categories.Category,Originations_Categories.Category_ID

FROM Originations_Categories

WHERE(((Originations_Categories.Product_ID )= 1))

ORDER BY Originations_Categories.Category;


我将Column Count设置为1,并将category_ID的绑定列设置为2。


我要做的是从我的组合框中选择8个类别中的一个,它将自动更新我的子表单中的该类别的问题。

我的子表单命名为:subfrm_OrigPL_Cat1

运行此子表单的查询命名为:subqry_frm_OrigPL_Cat1


我认为它只需要重新查询选择组合框类别后,此子查询。希望这不难。


非常感谢,

马特

I have a combo box called cmb_category. I then have the SQL statement as such:
SELECT Originations_Categories.Category, Originations_Categories.Category_ID
FROM Originations_Categories
WHERE (((Originations_Categories.Product_ID)=1))
ORDER BY Originations_Categories.Category;

And I have Column Count as 1 and bound column set to 2 for the category_ID.

What I am trying to do is Select one of the 8 Categories in my Combo box and it will automatically update my subform with the questions for that category.

My subform is named: subfrm_OrigPL_Cat1
My query that runs this sub form is named: subqry_frm_OrigPL_Cat1

I think it would just need to requery this sub query once the Combo box category is chosen. Hope this isn''t to difficult.

Thanks very much,

Matt

推荐答案

嗨马特。您没有提供任何有关组合框中列出的每个类别的问题的详细信息。如果每个类别有多个问题,最好的办法是使用记录集处理打开与您的类别匹配的相关问题集,循环记录集并相应地设置问题字段。这将由您的类别组合的After Update事件触发。


如果只有一个问题需要填写,那么更简单的方法是将问题包含在组合的记录源中查询,将组合中该列的宽度设置为0(隐藏额外列),然后使用组合的更新后事件将表单的问题设置为隐藏组合列的值(使用我! [组合名称] .Column(2)例如引用第三个组合列 - 列从0开始编号。


-Stewart
Hi Matt. You haven''t provided any details of how many questions there are for each category listed in your combo box. If you have multiple questions per category your best bet would be to use recordset processing to open the relevant set of questions matching your category, loop through the recordset and set your question fields accordingly. This would be triggered from the After Update event of your category combo.

A simpler approach if there was only one question to fill would be to include the question in the combo''s recordsource query, set the width of that column in the combo to 0 (to hide the extra column), then use the after update event of the combo to set the form''s question to the value of the hidden combo column (using Me![combo name].Column (2) for example to refer to the third combo column - columns being numbered from 0).

-Stewart


Stewart,


我尝试了第二部分你的列宽和AfterUpdate我的子表单。我不确定你在处理记录集时谈到了什么。但是每个类别下都有4到12个问题。我正在使用连续子表单列出所有不同的问题,并可以根据问题的数量向上和向下滚动。

你提到我试图做的第二部分,但我无法正常工作。我的组合框称为cmb_category,其列宽为1; 0; 0使用category_ID作为你建议的第三列,并使绑定列= 3.

然后对于我的子表单,我创建了AfterUpdate:

Private Sub Form_AfterUpdate()

我![cmb_category] ​​.Column(2)

End Sub


当我在下拉框中选择一个类别时它什么都没做。这个子表单基于一个查询,是否可以在选择类别时在After Update上执行某种DoCmd.requery?我不确定如何写这个如果你能帮忙我会很感激。


谢谢,


马特
Stewart,

I tried the second part you with the column width and AfterUpdate for my subform. I was unsure what you were talking about with the recordset processing. But under every Category has anywhere from 4-12 questions. I am using a continous subform to list all the different questions and can scroll up and down based on the number of questions.
The second part you mentioned I attempted to do, but I have not been able to get this work properly. My combo box is called cmb_category and have the column widths, 1";0";0" with the category_ID as the third column as you suggested and have the bound column = 3.
Then for my subform I created the AfterUpdate as such:
Private Sub Form_AfterUpdate()
Me![cmb_category].Column (2)
End Sub

When i pick a category in the drop down box it didn''t do anything. This subform is based on a query, is it something that i can do some sort of DoCmd.requery on the After Update when the category is selected? I am unsure exactly how to write that if you can help i would appreciate it.

Thanks,

Matt


我现在至少工作了两个小时。我通过网络搜索了一些网站,当我选择一个类别时,仍然没有任何内容可以更新我的子表单。我这么做的两件事是,我可以在子表单中列出所有问题(否定类别框的事实)。因此,它列出了我的子表单中的大约40个问题,这些问题通常归类于8个类别,并且在子表单中的问题较少。我正在研究的另一件事是在我的子查询中设置一个参数来填充我的子表单。我将组合框设置为默认值= 1,它显示了类别1的所有问题,但是如果我在组合框中更改类别,则没有任何反应。我已经尝试了Docmd.Requery和我在这个网站上看到的其他一些东西,但似乎并没有起作用。有任何想法吗?


谢谢,


马特
I have been working on this for at least two hours now. I have searched thru the web and some of this site and still nothing appears to update my subform when i choose a category. The two things I have done thusfar, is I can have all questions listed in the subform (negating the fact of the category box). So it lists about 40 questions in my subform that would normally categorized under the 8 categories and be less questions in the subform. The other thing I was working on is setting a parameter in my subquery that populates my subform. I set the combo box to default value = 1 and it shows me all of the questions for category 1, but if I change the category in the combo box, nothing happens. I have tried Docmd.Requery and a few other things I have seen on this web site, but doesn''t seem to be working. Any ideas?

Thanks,

Matt


这篇关于用于组合框和子表单的VB代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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