|
Public Function CopyRecord()
On Error GoTo Err_CopyRecord
Dim connSour As New ADODB.Connection
Dim connTar As New ADODB.Connection
Dim rsSour As New ADODB.Recordset
Dim rsTar As New ADODB.Recordset
Dim strSourceSQL As String, strTargetSQL As String
Dim i As Integer
Dim strConnectString As String
strConnectString = "provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\数据库\数据存储.mdb"
connSour.Open strConnectString
strSourceSQL = "select * from 源表"
rsSour.Open strSourceSQL, connSour, adOpenKeyset, adLockOptimistic
Set connTar = CurrentProject.Connection
strTargetSQL = "select * from 目标表"
rsTar.Open strTargetSQL, connTar, adOpenKeyset, adLockOptimistic
Do Until rsSour.EOF
rsTar.AddNew
For i = 0 To rsSour.Fields.Count - 1
rsTar.Fields(i) = rsSour.Fields(i)
Next
rsTar.Update
rsSour.MoveNext
Loop
rsSour.Close
rsTar.Close
connSour.Close
connTar.Close
Set connSour = Nothing
Set connTar = Nothing
Exit_CopyRecord:
Exit Function
Err_CopyRecord:
Set connSour = Nothing
Set connTar = Nothing
MsgBox Err.Description
Resume Exit_CopyRecord
End Function
|
|