添加到数组? [英] add to array?

查看:61
本文介绍了添加到数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我需要帮助设置并添加到阵列。虽然我已经使用了数组* * * *并了解它们的基本性质,但我从未在访问过程中这样做过。


好​​的,所以在我的表单上我有一个组合框用于 ;员工及QUOT ;.但是我需要能够让多个工作人员进入数据库(组合框本身是从一个单独的表中提供的),最好是一个字段。


所以我在想可能有一个按钮添加员工。因此,用户可以从下拉列表中选择第一个Staff成员,然后单击Add Staff member。这将清除组合框,以便他们可以选择另一个等等。每当他们选择另一个工作人员时,它将被附加到阵列。


这样的东西可以运作吗?有没有更好或更简单的方法来做这个没有为多个员工多个字段?我在这里试图避免空单元格,因为有一天用户可能有3名工作人员,第二天就有1或5.所以我不想设计主表有多个人员字段。相反,我认为有一个可以容纳多个值的字段会更好。


感谢您的帮助!

解决方案

我不会使用数组。这是用户和员工表之间的多对多连接。即一个用户可以有一个或多个工作人员,一个工作人员可以有一个或多个用户。您可以使用连接表来执行此操作,该连接表将具有其他两个表的主键的复合键。


例如,

tblStaffPerUser

StaffID(复合PK和工作人员PK的外键引用)

UserID(复合PK和用户表PK的外键引用) )


然后可以使用基于上表的子表格添加工作人员。


Mary


< blockquote>对不起,我不清楚。用户我的意思是填写表格的人。它实际上是用户和事件之间的一对多关系。所以在任何一个活动中都可以有一个或多个工作人员(虽然几乎总会有至少2个人参与一个活动)。


所以在事件表(tbl_Event)那里是Staff_ID(外键)的字段。在Staff表(tbl_Staff)中,有一个Staff_ID字段(主键)和Staff_Name。 tbl_Staff.Staff_Name为frm_Event提供了组合框,但是存储在tbl_Event中的是作为外键的Staff_ID字段。


所以我只需要能够存储多个Staff tbl_Event。存储Staff_Names还是Staff_ID会更好吗?如果不是阵列,最好的方法是什么?


感谢您的帮助!

melissa: - )


对不起,我不清楚。用户我的意思是填写表格的人。它实际上是用户和事件之间的一对多关系。所以在任何一个活动中都可以有一个或多个工作人员(虽然几乎总会有至少2个人参与一个活动)。


所以在事件表(tbl_Event)那里是Staff_ID(外键)的字段。在Staff表(tbl_Staff)中,有一个Staff_ID字段(主键)和Staff_Name。 tbl_Staff.Staff_Name为frm_Event提供了组合框,但是存储在tbl_Event中的是作为外键的Staff_ID字段。


所以我只需要能够存储多个Staff tbl_Event。存储Staff_Names还是Staff_ID会更好吗?如果不是阵列,最好的方法是什么?


感谢您的帮助!

melissa :-)


Melissa


这是同样的问题,但使用事件表而不是用户表。拥有外键的重点是将其绑定到另一个表。如果你在那里放置多个值,你就不能这样做。这仍然是一个多对多的关系,因为一个活动可以有一个或多个工作人员和工作人员可以分配到一个或多个事件。


这是唯一可以处理的方式是加入表。


Mary


Hello all,

I need help setting up and adding to an array. I have never done this in access before though I have worked with arrays a *little* bit and understand their basic nature.

Okay, so on my form I have a combo box for "Staff". But I need to be able to have multiple staff entered into the database (the combo box itself is fed from a separate table), and preferably into one field.

So I was thinking that there could be a button "Add Staff member". So the user could choose the first Staff member from the dropdown, then click "Add Staff member" which would clear the combo box so they could choose another etc. Every time they chose another staff member it would get appended to the array.

Could something like this work well? Is there a better or easier way to do this WITHOUT having multiple fields for multiple staff? I''m trying to avoid empty cells here because one day the user may have 3 staff members and the next day 1 or 5. So I don''t want to design the master table to have multiple staff fields. Rather I thought it would be better to have one field that can hold multiple values.

Thanks for any help!

解决方案

I wouldn''t do it using an array. This is a many to many join between the user and staff table. i.e. one user can have one or many staff and one staff can have one or many users. You would do this using a join table which would have a composite key of the primary keys of the other two tables.

For example,

tblStaffPerUser
StaffID (Composite PK and Foreign key reference to the PK of Staff table)
UserID (Composite PK and Foreign key reference to the PK of User table)

The staff could then be added using a subform based on the above table.

Mary


I''m sorry, I wasn''t clear. By user I meant the person filling out the form. It is actually a one to many relationship between user and event. So on any one event there can be one or many staff (although there will almost always be at least 2 people involved in an event).

So in the event table (tbl_Event) there is a field for Staff_ID (foreign key). In the Staff table (tbl_Staff) there is a Staff_ID field (primary key) and Staff_Name. tbl_Staff.Staff_Name feeds the combo box on the frm_Event but what gets stored in tbl_Event is the Staff_ID field that is the foreign key.

So I just need to be able to store multiple Staff in tbl_Event. Would it be better to store the Staff_Names or the Staff_ID? And what is the best way to do it if not an Array?

Thanks for the help!
melissa :-)


I''m sorry, I wasn''t clear. By user I meant the person filling out the form. It is actually a one to many relationship between user and event. So on any one event there can be one or many staff (although there will almost always be at least 2 people involved in an event).

So in the event table (tbl_Event) there is a field for Staff_ID (foreign key). In the Staff table (tbl_Staff) there is a Staff_ID field (primary key) and Staff_Name. tbl_Staff.Staff_Name feeds the combo box on the frm_Event but what gets stored in tbl_Event is the Staff_ID field that is the foreign key.

So I just need to be able to store multiple Staff in tbl_Event. Would it be better to store the Staff_Names or the Staff_ID? And what is the best way to do it if not an Array?

Thanks for the help!
melissa :-)

Melissa

This is the same problem but with the event table rather than the user table. The whole point of having a foreign key is to tie it to the other table. If you put multiple values in there you can''t do that. This is still a many to many relationship as an event can have one or many staff and staff can be assigned to one or many events.

The only way this can be handled is with a join table.

Mary


这篇关于添加到数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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