[英]MS Access sub-subform data entry
I am building a communication/task logging system which logs incoming communications and assigns tasks based on them. 我正在构建一个通信/任务记录系统,该系统记录传入的通信并根据它们分配任务。
My database has a notes system, so that the users can make notes about a variety of things - eg a customer record might have a note which says "This customer always orders their own window frame glass". 我的数据库有一个便笺系统,以便用户可以对各种事情做便笺-例如,客户记录中可能有一个便笺,上面写着“该客户总是订购自己的窗框玻璃”。 This is all handled via a single "Notes" table which has a PrimaryNoteTableID
which links to a static lookup table which identifies the primary table which the note applies to, and an PrimaryTablePK
field which stores the PK of the record within that table it applies to. 所有这些操作都通过一个单独的“ Notes”表进行处理,该表具有一个PrimaryNoteTableID
和一个PrimaryTablePK
字段,该静态查找表标识了该注释所适用的主表,该静态查找表标识了该注释所适用的主表, PrimaryTablePK
字段存储了该表在该表中的记录。
In order to avoid corruption, it is advised to keep memo fields in a table of their own with a 1:1 relationship to their parent table ( see here ), which is what I have done. 为了避免损坏,建议将备注字段保留在自己的表中,该表与它们的父表保持1:1的关系( 请参阅此处 ),这是我所做的。
When adding new communications and tasks, the user will usually want to add the following: 在添加新的通信和任务时,用户通常将需要添加以下内容:
With that in mind I have: 考虑到这一点,我有:
tblCommTaskLog
with the fields CommDate
, ActionRequiredTypeID(FK)
, ActionDeadlineDays
, CommAccountID(FK)
etc. tblCommTaskLog
,其字段为CommDate
, ActionRequiredTypeID(FK)
, ActionDeadlineDays
, CommAccountID(FK)
等。
tblNote
with: NoteID(PK)
, PrimaryNoteTableID(FK)
, PrimaryTablePK(FK)
, EnteredByUserID(FK)
, EntryDate
. tblNote
具有: NoteID(PK)
, PrimaryNoteTableID(FK)
PrimaryTablePK(FK)
, EnteredByUserID(FK)
, EntryDate
EnteredByUserID(FK)
, EntryDate
。
tblNoteText
with NoteTextID(PK)
, NoteID(FK)
, NoteText(Memo)
tblNoteText
与NoteTextID(PK)
, NoteID(FK)
, NoteText(Memo)
Some of these are foreign keys to other tables which should be self-explanatory. 其中一些是其他表的外键,这些表应该是不言自明的。
Essentially what I'm running into problems with is the form for entry with these three tables. 本质上,我遇到问题的是这三个表的输入表单。 I find that the Access handling of subforms can be pretty stupid, such that: 我发现子窗体的Access处理可能非常愚蠢,例如:
I'd like to just have the fields from tblCommTaskLog
and the NoteText
field on one form, so that the user fills in the details from tblCommTaskLog
(ActionRequired etc.) and the note text, hits a "Save" button, and then via code the items are saved correctly, such that: 我想只是从田野tblCommTaskLog
和NoteText
一种形式的领域,从而使从细节用户填写tblCommTaskLog
(ActionRequired等)和注释文本,点击“保存”按钮,然后通过代码这些项目已正确保存,例如:
tblCommTaskLog
with eg a PK of 72
(Autonumber). 在tblCommTaskLog
创建一个新记录,例如PK为72
(自动编号)。 tblNote
with a PrimaryNoteTableID
of 4
which corresponds to tblCommTaskLog
, a PrimaryTablePK
of 72
and a PK NoteID
eg 422
(Autonumber). 一个新的记录中创建tblNote
与PrimaryNoteTableID
的4
对应于tblCommTaskLog
,一个PrimaryTablePK
的72
和PK NoteID
例如422
(自动编号)。 tblNoteText
with a NoteID
of 422. 在tblNoteText
创建一个新记录,其NoteID
为422。 I think what I need is a main form with the fields from tblCommTask
with an unbound text field to take the input for NoteText
. 我认为我需要的是一种主要形式,其中包含来自tblCommTask
的字段以及未绑定的文本字段,以接收NoteText
的输入。 I just can't figure out how to create a new record in tblNote
, get the AutonumberPK from that field and insert it into the FK of tblNoteText
such that everything is linked together correctly with the right FKs. 我只是不知道如何在tblNote
创建新记录,从该字段中获取AutonumberPK并将其插入tblNoteText
的FK中, tblNoteText
使所有内容都与正确的FK正确链接在一起。 Can I do this with an SQL INSERT and then a SELECT TOP on the Autonumber field? 我可以使用SQL INSERT然后在Autonumber字段上使用SELECT TOP来做到这一点吗? Would I be better off doing this with Recordsets and Lastmodified? 使用Recordsets和Lastmodified这样做会更好吗? Is there some other method I'm not thinking of? 还有我没有想到的其他方法吗?
@whatEvil: @whatEvil:
you can still make it as 1:M. 您仍然可以将其设置为1:M。 if you are allowed to alter your primary tables, alter them and add 如果允许您更改主表,请对其进行更改并添加
in your tbl_note just have 在您的tbl_note中
now you can simply enforce 1:M relationship. 现在您只需执行1:M关系即可。 GUID are "Globally Unique Identifier". GUID是“全局唯一标识符”。 All of your primary tables will produce an unique key where you can simply join them at any stage without thinking of which table it belongs to or how to save parent table name. 您所有的主表都将产生一个唯一键,您可以在任何阶段简单地将它们联接,而无需考虑它属于哪个表或如何保存父表名。
of course you need a custom function to get GUIDs: use this code to create one 当然,您需要一个自定义函数来获取GUID:使用此代码创建一个
Public Function GET_UUID() As String
With CreateObject("Scriptlet.TypeLib")
GET_UUID = VBA.Left(.GUID, 38)
End With
End Function
Edit: The idea is to have a global unique id in each of your primary table (GUID/ UUID). 编辑:想法是在每个主表(GUID / UUID)中都有一个全局唯一ID。 Which then will be used to join your primary and note table. 然后将其用于连接您的主要表和注释表。 Note: you need to add a trigger (before insert) to each of your primary table to produce a GUID. 注意:您需要在每个主表中添加一个触发器(在插入之前),以产生一个GUID。 Also note, MS access call it DataMacro (check if your version support datamacro) more about datamacro : https://support.office.com/en-ca/article/Create-a-data-macro-b1b94bca-4f17-47ad-a66d-f296ef834200?ui=en-US&rs=en-CA&ad=CA 另请注意,MS访问将其称为DataMacro(检查您的版本是否支持datamacro)有关datamacro的更多信息: https : //support.office.com/en-ca/article/Create-a-data-macro-b1b94bca-4f17-47ad- a66d-f296ef834200?ui = zh-CN&rs = en-CA&ad = CA
why this way? 为什么这样呢? currently your primary tables are producing Auto-number it is possible that one or more table will have same ID number. 当前,您的主表正在生成自动编号,一个或多个表可能具有相同的ID号。 After all, autonumber is only unique throughout a table not throughout the entire database. 毕竟,自动编号仅在整个表中唯一,而不在整个数据库中唯一。 To avoid duplicating you are adding another key (table identification key) to identify to which primary table the foreign key belongs to. 为避免重复,您要添加另一个键(表标识键)以标识外键所属的主表。 this sounds all good until you make one wrong update to your primary table with wrong value to the note ID. 这听起来很不错,直到您对主表进行了一次错误的更新,并为便笺ID设置了错误的值。
by using GUID you will be able to simply maintain the 1:m relationship no matter how many primary tables are participating. 通过使用GUID,无论有多少个主表参与,您都可以简单地保持1:m关系。 Also I personally like the idea with GUID in case if your application grows and need real unique ids throughout your database. 我个人也喜欢GUID的想法,以防您的应用程序增长并且在整个数据库中需要真正的唯一ID。 its totally up to you which way you want to go, i just explained one method.. 这完全取决于您,您想走哪条路,我只是解释了一种方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.