如果您正試圖將其插回相同的表,那麼你可以不用蒲凌成一個記錄都沒有。
您只需編寫正確的SQL查詢並執行它。
您選擇的數據將是您已經使用更新的值提取的記錄集。
例如:
INSERT INTO tableX(field1, productId, productDesc)
SELECT field1, 777 as productId, "NewString" as productDesc
FROM tableX
WHERE productId=7
我在評論中提到將遍歷每個字段的建設作爲SQL命令你的字符串的另一種方法,在此執行將是快了很多,然後按記錄處理記錄。 (如插入一個新的產品,用於在訂單表中的每個訂單,其中其他產品已經被訂購,這可能會對訂單的1000個10秒)
'Edited the code supplied by another response above'
Sub CopyProductRow()
Dim sFld, iField, sqlQuery As String
i= "INSERT INTO products("
s= "SELECT "
w= "WHERE ProductID = 7"
For Each fld In rsSrc.Fields
Select Case fld.Name 'Check the field name'
' special cases'
Case "ProductID": 'If field is Product ID'
iFld = "777 as ProductID" '777 will be the product id returned by the select query (therefore inserted)'
Case "ProductDesc": 'If field is Product Description '
'The description below will be selected/inserted instead.'
iFld = "'New Product Description' as ProductDesc"
Case Else:
iFld = fld.Name 'No change just select the field and insert as is.'
End Select
i = i & ", " & fld.Name
s = s & ", " & iFld
Next fld
'Build complete query (removing the first comma in the select statement)'
sqlQuery = i & ") " & replace(s, "SELECT ,", "SELECT ") & " " &w
'Resulting in a string such as the following'
'INSERT INTO products(field1,field2, productId, productDesc, field5, ...)'
'SELECT field1, field2, 777 as ProductID, 'New Product Description' as ProductDesc, field5, ...'
'FROM tableX'
'WHERE productId=7'
'Print the query to immediate window
Debug.print sqlQuery
'Execute the query'
currentdb.execute sqlQuery
End Sub
你看着查詢設計窗口? – Fionnuala