如何将可编辑的列添加到不可编辑的查询

问题描述:

我在子窗体的数据表视图中有一个查询,其中包含用户需要添加的信息.具体来说,需要编辑2列.由于大量的GROUP BY子句,因此该查询不可编辑.有没有一种方法我可以添加这2列,并使它们每行可编辑,而无需更改查询/将其重写以使其可编辑?

I have a Query in Datasheet View in a Subform which holds information that the user needs to add to. Specifically, 2 columns need to be edited. The Query is non-editable because of a ton of GROUP BY clauses. Is there a way that I can add these 2 columns and make them editable per row without changing the query/rewriting it to make it editable?

到目前为止,我已经尝试添加未绑定的列,但这并不保存每一行的数据.现在,我已经设置了一个新表,其中有两列我想添加为控制源",但是由于记录是只读的,因此我无法编辑数据表中的任何内容.

So far, I've tried adding an unbound column but that doesn't hold the data per row. Now, I've set a new table with the two columns I want to add as Control Source but I can't edit anything in the Datasheet because the record is read-only.

您无法在分组查询中进行编辑,因为无法告知数据库您实际上在编辑哪些分组记录.您没有提到是否仅在表单上下文中需要这些列即可编辑(并且在关闭或重新加载其他数据后,这些列中的所有数据都会被丢弃),或者这些编辑是否有望以某种方式更新您的记录.

You cannot edit in a grouped query because there is no way to tell the database which of the grouped records you are actually editing. You do not mention if you need these columns editable just in he context of the form (and any data in them is thrown away as soon as the form is closed or reloaded with different data) or if these edits are expected to somehow also update your records.

在任何一种情况下,执行此操作的方式都是使用临时表并用查询数据填充它.这样一来,您就可以在数据表视图中对其进行编辑并维护每个记录的值.但是,如果您希望这些值以某种方式永久性地影响原始数据,则必须在VBA中手动处理该数据,可能会捕获表单关闭或重新加载事件,并使用临时表数据来更新原始表.

In either case the way to do it is by using a temporary table and fill it with the query data. That will allow you to edit it in datasheet view and maintain per-record values. However if you expect these values to somehow permanently affect your original data you will have to manually handle that in VBA, probably capturing form close or reload events and using the temporary table data to update the original tables.