简体   繁体   English

如何使用组合框显示一个表中的数据,然后使用MS Access将其添加到另一个表中?

[英]How can I use a combo box that displays data from one table and add it to another using MS Access?

I am developing a database system. 我正在开发数据库系统。 It is for a canoe club. 这是一个独木舟俱乐部。 The part of the database I am stuck on is assigning a member of the canoe club to a canoe qualification course when/if they undertake one. 我坚持的数据库部分是在/如果他们进行的话,将独木舟俱乐部的成员分配给独木舟资格课程。

Here is a stripped down view of my tables: 这是我的表格的简化视图:

members
-------------------------------------
| memberID | first_name | last_name |
-------------------------------------
| 1        | John       | Jacobs    |
| 2        | Ellie      | Graham    |
| 3        | Paul       | Abbot     |
-------------------------------------

course_info
---------------------------------------
| courseID | course_name | Instructor |
---------------------------------------
| 1        | BCU Level 1 | Ryan Adams |
| 2        | BCU Level 2 | Ryan Adams |
| 3        | BCU Level 3 | Ryan Adams |
| 4        | BCU Level 4 | Ryan Adams |
| 5        | BCU Level 5 | Ryan Adams |
---------------------------------------

course_progress
-------------------------------
| memberID | courseID | grade |
-------------------------------
| 1        | 2        | 4     |
| 1        | 4        | 5     |
| 2        | 1        | 3     |
| 3        | 5        | 2     |
-------------------------------

So as you can see, course_progress displays the courses a member has undertaken as well as their grade by using memberID and courseID . 如您所见, course_progress通过使用memberIDcourseID来显示成员course_progress的课程及其成绩。

Firstly is that the correct (or a correct) way of doing this? 首先,这是正确的方法吗? If so, here is my problem... 如果是这样,这是我的问题...

Using Access I want to create a form that allows me to assign a member to a course. 使用Access我想创建一个表格,允许我向课程分配成员。 So I have a combo box that lists all of the members and another that lists all of the courses. 因此,我有一个列出所有成员的组合框,并列出了所有课程的组合框。 As well as a box for inputting the grade. 以及用于输入成绩的方框。

When I fill in this form it only adds the grade to the course_progress table. 当我填写此表格时,它只会将成绩添加到course_progress表中。 I feel as though this is the case because I am using fields from different tables in the combo box. 我感觉好像是这种情况,因为我在组合框中使用了来自不同表的字段。 The other solution that while works is less than ideal is to have memberID and courseID in the combo box. 另一种memberID解决方案并不理想,那就是在组合框中包含memberIDcourseID I believe that works as I am using fields from the table I am trying to add to. 我认为这可以正常工作,因为我正在使用要添加到的表中的字段。 However it is not user friendly as ID's are meaningless to a user. 但是,它对用户不友好,因为ID对用户毫无意义。

So I want to be able to select the member name and course name from the combo box and add them to the course_progress table as well as the grade. 因此,我希望能够从组合框中选择成员名称和课程名称,并将它们添加到course_progress表以及成绩中。

Any guidance would be great. 任何指导都会很棒。

Thanks. 谢谢。

Firstly, is your form bound to the course_progress table., and are the two combo boxes bound to the memberID and courseID fields of the progress table. 首先,将您的表单绑定到course_progress表上,并将两个组合框绑定到进度表的memberID和courseID字段上。

Secondly, what have you used as the query for each combo box. 其次,您使用什么作为每个组合框的查询。 You should be querying the members table. 您应该查询成员表。 Assuming you do, you will have 3 columns, the first being the member ID and that should be the "bound column" in the combo box properties. 假设您这样做,您将有3列,第一列是成员ID,并且应该是组合框属性中的“绑定列”。 in the format section you will need to give column widths, and I would give the memberID column a width of 0 so it doesn't show. 在格式部分,您将需要指定列的宽度,而我将memberID列的宽度设置为0,这样它就不会显示。 But you should say you want to display 3 columns (so you get firstname and last name in the combo box. 但是您应该说您想显示3列(因此您会在组合框中获得名字和姓氏。

Do the same for the course combo box. 对课程组合框执行相同的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM