I have to append 3 millions of records from MS access table to SQL Server Table, below is the VBA code for the same, This code is correct but it is taking lot of time (2000 Records Per Minute) to append 3 Millions records.
can you please help me to reduce processing time.
Private Sub cmdMoveToServer_Click()
Dim cmd As New ADODB.Command, RSdao As DAO.Recordset, RecordsCounts As Long
RecordsCounts = 0
Dim con As ADODB.Connection
Dim SQLStr As String
cmd.ActiveConnection = "Driver={SQL Server};Server=" & Server_Name & ";Database=" & Database_Name & _
";Uid=" & User_ID & ";Pwd=" & Password & ";"
cmd.ActiveConnection.CursorLocation = adUseClient
cmd.CommandType = adCmdText
cmd.CommandText = "Truncate Table SQL_Server_Table" '--clear out contents of my table in Sql Server DB
cmd.Execute
Set RSdao = CurrentDb.OpenRecordset("Local_MS_Access_Table") '--local MS Access Table
DoEvents
Do While Not RSdao.EOF
cmd.CommandText = "Insert Into SQL_Server_Table Select '" & RSdao(0) & "', '" & RSdao(1) & "', '" & RSdao(2) & "', '" & RSdao(3) & "', '" & RSdao(4) & "', '" & RSdao(5) & "'"
cmd.Execute
RSdao.MoveNext
RecordsCounts = RecordsCounts + 1
Me.lblQueryCount.Caption = RecordsCounts & " Records Moved."
DoEvents
Loop
RSdao.Close
cmd.ActiveConnection.Close
Debug.Print "Done"
End Sub
can you please help me to reduce processing time.
Private Sub cmdMoveToServer_Click()
Dim cmd As New ADODB.Command, RSdao As DAO.Recordset, RecordsCounts As Long
RecordsCounts = 0
Dim con As ADODB.Connection
Dim SQLStr As String
cmd.ActiveConnection = "Driver={SQL Server};Server=" & Server_Name & ";Database=" & Database_Name & _
";Uid=" & User_ID & ";Pwd=" & Password & ";"
cmd.ActiveConnection.CursorLocation = adUseClient
cmd.CommandType = adCmdText
cmd.CommandText = "Truncate Table SQL_Server_Table" '--clear out contents of my table in Sql Server DB
cmd.Execute
Set RSdao = CurrentDb.OpenRecordset("Local_MS_Access_Table") '--local MS Access Table
DoEvents
Do While Not RSdao.EOF
cmd.CommandText = "Insert Into SQL_Server_Table Select '" & RSdao(0) & "', '" & RSdao(1) & "', '" & RSdao(2) & "', '" & RSdao(3) & "', '" & RSdao(4) & "', '" & RSdao(5) & "'"
cmd.Execute
RSdao.MoveNext
RecordsCounts = RecordsCounts + 1
Me.lblQueryCount.Caption = RecordsCounts & " Records Moved."
DoEvents
Loop
RSdao.Close
cmd.ActiveConnection.Close
Debug.Print "Done"
End Sub