用于向用户分配类别的 MS 访问表单
我遇到了一个小问题。我使用的是 MS Access 2003(我们的服务器上也是 2010)。
我有一个用户表、一个类别表和一个 user_to_category 表。
我将如何创建一个显示所有类别(带有复选框)的表单,当我单击每个类别时,它会将类别 ID 和用户 ID(来自会话)添加到 user_to_category 表中。
我创建了单独的复选框并使用了 onClick 事件,但我需要动态加载类别列表,因为人们会添加更多类别,而我不想手动添加它们。
有什么想法吗?我考虑过使用带有类别的列表框,然后允许用户选择多个条目 - 然后将其添加到表中..但不确定这是最好的方法吗?
感谢您提供任何信息!
I am stuck with a little problem. I am using MS access 2003 (also 2010 on our server).
I have a table of users, a table of categories and a table for user_to_category.
How would I create a form which shows all the categories (with tick boxes) and as I click on each one, it adds that categoryID and userID (from session) to the user_to_category table.
I created individual checkboxes and used the onClick event, but I need to dynamically load the list of categories as people will add more and I don't want to manually add them.
Any ideas? I thought about using a listbox with the categories, then allowing a user to select multiple entries - this is then added to the table.. but not sure that's the best way?
thanks for any info!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
创建一个连续表单,将此查询作为其记录源,并将该表单命名为 frmUsers。
使用此记录源创建第二个表单fsubUserCategories。
添加一个用于category_name 的绑定文本框,以及一个绑定到categoryID 的组合框cboCategoryID。使用此查询作为组合的行源属性。
展开 frmUsers 的页脚部分,并将 fsubUserCategories 添加到页脚中的子表单控件。使用 userID 作为子表单控件上的链接主/子属性。
通过这种安排,子表单将为与主表单 (frmUser) 中的当前用户关联的每个类别分配显示一行。
使用 frmUsers On Current 事件重新查询子表单组合 --- 因此它会更新为仅包含当前用户可用(未分配)的类别。
Form_frmUsers:
在 fsubUserCategories 中,再次从“删除后确认”、“插入后”和“更新后”事件中重新查询 cboCategoryID,以便更新为仅包含当前用户可用的未分配类别。
Form_fsubUserCategories:
此方法允许您查看每个用户的类别分配。您还可以从子表单中添加或删除行来管理这些分配。
Create a continuous form with this query as its record source, and name the form frmUsers.
Create a second form, fsubUserCategories, with this record source.
Add a bound text box for category_name, and a combo box, cboCategoryID, bound to categoryID. Use this query as as the combo's row source property.
Expand the footer section of frmUsers and add fsubUserCategories to a subform control in the footer. Use userID as the link master/child properties on the subform control.
With that arrangement, the subform will display a row for each category assignment associated with the current user in the main form (frmUser).
Use frmUsers On Current event to requery the subform combo --- so it gets updated to contain only the available (unassigned) categories for the current user.
Form_frmUsers:
In fsubUserCategories, requery cboCategoryID from the After Delete Confirm, After Insert, and After Update events --- again so that it gets updated to contain only the unassigned categories available for the current user.
Form_fsubUserCategories:
This approach will allow you to view the category assignments for each user. You can also add or delete rows from the subform to manage those assignments.
当您使用 MS Access 时,最简单的方法是创建一个连续表单,其中类别表作为 RecordSource。
您可以在复选框的 onClick 事件中检查当前类别(=刚刚单击的类别),只需在表单上放置一个带有类别 ID 的文本框并检查文本框的值(它将始终包含 ID)当前单击的记录)。
As you're using MS Access, the easiest way to do this is to create a continuous form with the categories table as RecordSource.
You can check in the onClick event of the checkbox which category is the current one (= the one that was just clicked) by just putting a textbox with the categoryID on the form and checking the value of the textbox (it will always contain the ID of the currently clicked record).