访问:使用 VBA 将查询结果复制到表中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42528479/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 12:12:41  来源:igfitidea点击:

ACCESS: copy result of query into table with VBA

vbams-access

提问by MES

i want to copy the result of my queries into a table.

我想将我的查询结果复制到一个表中。

i tried this:

我试过这个:

Function queryintotable()

Dim rs As New ADODB.Recordset

DoCmd.SetWarnings False

rs.CursorLocation = adUseClient    
rs.Open "target_table", CurrentProject.Connection
rs.Sort = "Retail_ID ASC"

Do Until rs.EOF = True
    DoCmd.CopyObject , "myquery", acQuery, "target_table"    
    rs.MoveNext
Loop

rs.Close

DoCmd.SetWarnings True
MsgBox ("Finish! " & Time)

End Function

but i think i forgot something. could u help me please thanks!

但我想我忘记了一些东西。你能帮我吗谢谢!

回答by marlan

One line of code:

一行代码:

CurrentDB.Execute "Select myquery.* Into target_table From myquery"

Will create a table named target_tablecontaining the result set of myquery.

将创建一个名为的表,target_table其中包含myquery.

CurrentDB.Execute "Insert Into target_table Select myquery.* From myquery"

Will insert the result set of myqueryto an already existing table named target_table, with the same structure.

将 的结果集插入myquery到一个名为 的现有表中target_table,具有相同的结构。