在Access中我试图编写一些代码,只将一行中的所有行复制到另一个表中。
我试图不使用SQl,这是希望VB执行此操作会更快,目前用于执行此工作的查询需要一个小时。
它在第一条记录中断,“记录被删除”。虽然记录导出的表中有记录。
我想知道是否有人对如何解决此问题有任何想法?
或者如果我以错误的方式解决这个问题?
Public Sub ClientsImport()
Dim rs As Recordset, rsIN As Recordset
Dim db As Database
Set db = CurrentDb()
Set rs = db.OpenRecordset("tblDIFCClients_Import2", dbOpenDynaset)
Set rsIN = db.OpenRecordset("tblDIFCClients_import_IN", dbOpenDynaset)
Logit "Start:tblDIFCClients_import..."
DoCmd.RunSQL ("delete * from tblDIFCClients_import_IN")
Logit "... Cleared holding table..."
CurrentDb.Execute ("qryMatch_TblClients1")
Logit "... Grabbed from Server..."
Logit "... Updating Live table..."
DoCmd.RunSQL ("delete * from tblDIFCClients_import2")
Logit "Append Clients"
rsIN.MoveFirst
With rs
Do Until rsIN.EOF
.AddNew
![fldDIFCClientsRAWID] = rsIN![fldDIFCClientsRAWID]
![fldClientID] = rsIN![fldClientID]
![fldClientname] = rsIN![fldClientname]
![fldStyleSheet] = rsIN![fldStyleSheet]
![fldcustomjs] = rsIN![fldcustomjs]
![fldBannerImage] = rsIN![fldBannerImage]
![fldLogoImage] = rsIN![fldLogoImage]
![fldVanityURL] = rsIN![fldVanityURL]
![fldDescription] = rsIN![fldDescription]
![fldBusinessNumber] = rsIN![fldBusinessNumber]
![fldBasePrimaryColour] = rsIN![fldBasePrimaryColour]
![fldDefaultForwardingEmail] = rsIN![fldDefaultForwardingEmail]
![fldHasPFPs] = rsIN![fldHasPFPs]
![fldHasMicrosite] = rsIN![fldHasMicrosite]
![fldHasEvents] = rsIN![fldHasEvents]
![fldDateTimeStamp] = rsIN![fldDateTimeStamp]
![fldModified] = rsIN![fldModified]
![fldDownloaded] = rsIN![fldDownloaded]
![fldIgnore] = rsIN![fldIgnore]
.Update
rsIN.MoveNext
End With
rs.Close
Set rs = Nothing
rsIN.Close
Set rsIN = Nothing
Logit "End: Clients Import"
Logit ""
Debug.Print "Done:Clients"
答案 0 :(得分:0)
首先,我真的不认为循环记录集比通过SQL复制表更快。
实际上,您的代码在读取之前正在删除您正在从复制的表的内容,因此row is deleted
错误。您从tblDIFCClients_import_IN
获得记录集:
Set rsIN = db.OpenRecordset("tblDIFCClients_import_IN", dbOpenDynaset)
删除其内容:
DoCmd.RunSQL ("delete * from tblDIFCClients_import_IN")
然后尝试从中读取:
Do Until rsIN.EOF
您正在执行qryMatch_TblClients1
。这会填充tblDIFCClients_import_IN
吗?如果是这样,那就是您期望加载到tblDIFCClients_Import2
中的内容,那么在执行Set rsIN = db.OpenRecordset...
的调用之后,简单地移动qryMatch_TblClients1
行将发生解决它。