vba MS Access:以编程方式复制/粘贴所选记录?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2700932/
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
MS Access: Copy/Paste selected record programmatically?
提问by webworm
Sorry for the lengthy introduction but I think it best to explain the context of my question. I have an Access 2003 database in which users need to create new records based upon pre-existing records already in the table. Some of the users of the database are more familiar with computers in general and create a new record by ...
抱歉冗长的介绍,但我认为最好解释我的问题的背景。我有一个 Access 2003 数据库,其中用户需要根据表中已有的记录创建新记录。数据库的一些用户通常更熟悉计算机,并通过...创建新记录。
1. Selecting a previous record in a datasheet and copying it (via right click -> Copy)
2. Selecting new row in the datasheet and "pasting" the previous record (via right click => Paste)
3. Edit the newly pasted row with the new data
This works fine as the table the datasheet is based on uses an "auto-number" field preventing duplicates. The problem I am having is that some of the users of this database are not so "computer-savy" and are having some difficulty with right-clicking etc ... I have been asked to create a button that ..
这工作正常,因为数据表所基于的表使用“自动编号”字段防止重复。我遇到的问题是,该数据库的某些用户不是那么“精通计算机”,并且在右键单击等方面遇到了一些困难......我被要求创建一个按钮......
1. Copies the previous record
2. Inserts it into datasheet
The users can then edit the new record as needed. This leads me to my question. How do I go about copying a record and then inserting it into the datasheet programmatically in VBA? Thanks for any suggestions.
然后用户可以根据需要编辑新记录。这引出了我的问题。如何在 VBA 中以编程方式复制记录然后将其插入到数据表中?感谢您的任何建议。
采纳答案by Fionnuala
Use an Append query.
使用附加查询。
Some notes:
一些注意事项:
s = "Insert Into TableX (Field1, Field2, Field3) " _
& "Select Field1, Field2, Field3 From TableX " _
& "Where ID=" & Forms!TableXForm!ID
CurrentDb.Execute s
Forms!TableXForm.Requery