我想将查询结果复制到表格中。
我试过这个:
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
但我想我忘记了什么。请帮助我,谢谢!
答案 0 :(得分:4)
一行代码:
CurrentDB.Execute "Select myquery.* Into target_table From myquery"
将创建一个名为target_table
的表,其中包含myquery
的结果集。
CurrentDB.Execute "Insert Into target_table Select myquery.* From myquery"
将myquery
的结果集插入到已存在的名为target_table
的表中,具有相同的结构。