[英]How can I append records (specific rows, with multiple (but not all) columns) from one table to another
Each day ~5000 records are uploaded to tblRecordsCurrent, at some point within the next few days when those records have been processed, they need to be moved to tblRecordsHistorical. 每天约有5000条记录上载到tblRecordsCurrent,在处理这些记录后的几天之内的某些时候,需要将它们移到tblRecordsHistorical。 Each record has a Foreign Key
DataSetID
that ties it to the date/time it was uploaded (Parent Table). 每个记录都有一个外键
DataSetID
,可将其与上载日期/时间(父表)联系起来。
How, within vba, can I insert a single DataSet of tblRecordsCurrent into the tblRecordsHistorical from tblRecordsCurrent. 如何在vba中如何将tblRecordsCurrent的单个数据集从tblRecordsCurrent插入tblRecordsHistorical。 I cannot insert all columns as both tables contain persisted columns.
我不能插入所有列,因为两个表都包含持久列。
I can't put the entire INSERT INTO tblRecordsHistorical A, B, C, D, E, F...
as it is too long for access vba. 我无法将整个
INSERT INTO tblRecordsHistorical A, B, C, D, E, F...
,因为访问vba太长了。
Any ideas? 有任何想法吗?
If you save the query in your Access database, then you can execute in in VBA the following way: 如果将查询保存在Access数据库中,则可以通过以下方式在VBA中执行:
DoCmd.OpenQuery "yourQueryName", acViewNormal, acEdit
Or 要么
CurrentDb.OpenRecordset("yourQueryName")
Or 要么
CurrentDb.Execute "qryAddLoginfoRow"
This allows you to execute the query without having the query stored in your VBA code. 这使您无需将查询存储在VBA代码中即可执行查询。 But you are also able to execute this via a query in
VBA
: 但是您也可以通过
VBA
的查询执行此操作:
INSERT INTO tblRecordsHistorical (col1, col2...)
SELECT col1, col2...
FROM tblRecordsCurrent
EDIT: 编辑:
You can create a long SQL string by concatenating the string together: 您可以通过将字符串串联在一起来创建长SQL字符串:
SQLString = "INSERT INTO tblRecordsHistorical (col1, col2...) " & _
" SELECT ... " & _
" FROM tblRecordsCurrent "
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.