database 将一个字段复制到 access 中的另一个字段
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29553454/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
copy one field to another field in access
提问by Turniipp
I have hit a roadblock in my access form and I've searched high and low for an answer. I have a form (Enter Numbers) in which users enter information that obviously is stored in a table (Numbers). I need to have a field (# of models) in the numbers table, however, I don't want to ask the users to input that information. Furthermore, in another table (property info) I have that information already inputted. Now before you tell me that it is redundant...blah blah blah, to store the same information in two tables.....the (# of models) field in the (property info) table may change, whereas by storing that number in the (numbers) table each time users enter info in the form, I'm getting a snapshot that will not change.
我在访问表单中遇到了障碍,我在高低处寻找答案。我有一个表单(输入数字),用户可以在其中输入显然存储在表格中的信息(数字)。我需要在数字表中有一个字段(模型数),但是,我不想让用户输入该信息。此外,在另一个表(财产信息)中,我已经输入了该信息。现在,在你告诉我它是多余的......等等之前,将相同的信息存储在两个表中......(属性信息)表中的(模型数量)字段可能会发生变化,而通过存储该信息每次用户在表单中输入信息时(数字)表中的数字,我都会得到一个不会改变的快照。
I have a textbox that uses a dlookup function to pull the (# of models) from the (property info) table and displays it in the form. I had (and have no clue why it no longer functions properly) a button in the form, that when pushed would run the following code " text66 = models " Then I had a docmd.close so that it would put the dlookup result located in field (models) into (text66) whose control source is the field (# of models) in the (numbers) table. This was functioning flawlessly, and then something happened, and now when I click the button I receive a "you can't assign a value to this object" error.
我有一个文本框,它使用 dlookup 函数从(属性信息)表中提取(模型数量)并将其显示在表单中。我有(并且不知道为什么它不再正常工作)表单中有一个按钮,当按下它时会运行以下代码“ text66 = models ”然后我有一个 docmd.close 以便它将 dlookup 结果放在字段(模型)转换为(text66),其控制源是(数字)表中的字段(模型数量)。这运行完美,然后发生了一些事情,现在当我单击按钮时,我收到“您无法为该对象分配值”错误。
I don't care by what method I copy the dlookup result into the (numbers) table, but I would certainly appreciate any help in doing so! Thanks.
我不在乎通过什么方法将 dlookup 结果复制到(数字)表中,但我当然会感谢这样做的任何帮助!谢谢。
回答by Gord Thompson
With Access 2010 and later you could use a Before Change data macroon the [Numbers] table to grab a copy of the value from the other table:
使用 Access 2010 及更高版本,您可以使用[Numbers] 表上的Before Change数据宏从另一个表中获取值的副本:
回答by Boris
I believe this may work for you:
我相信这可能对你有用:
Use an update query. Add the second field, if you need to. Open the query designer. Drag the source field and destination fields onto the query designer. Open the sql view and make your code look like this:
使用更新查询。如果需要,添加第二个字段。打开查询设计器。将源字段和目标字段拖到查询设计器上。打开 sql 视图并使您的代码如下所示:
UPDATE table name
SET field2 = field1;
更新表名
SET field2 = field1;
Now execute the query.
现在执行查询。
field2 is the field you want data copied to. field1 is where the data resides.
field2 是您要将数据复制到的字段。field1 是数据所在的位置。
There was a thread hereregarding a similar question.
有一个线程在这里就类似的问题。
回答by StrGer GerStr
This is the simpliest way (I think) :
这是最简单的方法(我认为):
CurrentDb.Execute "update TableName SET TargetField=SourceField", dbFailOnError