Hi guys,
I'm using update query to update values in table. However it takes about an hour to finish updating. I found that there is possibility to use this code to increase the speed of the query:
However, I don't know where should I write this code. Should I write this into SQL statement, or as some VBA code? Currently my update query looks like this (See attachement).
I'm using update query to update values in table. However it takes about an hour to finish updating. I found that there is possibility to use this code to increase the speed of the query:
Code:
Sub PMUpdate()
Dim dbs As DAO.Database
Dim rsWk as DAO.Recordset
Dim strSQL,i As String
[B]Dim wksp As DAO.Workspace[/B]
Set dbs = CurrentDB()
[B]Set wksp = DBEngine.Workspaces(0) ' set up a transaction buffer[/B]
[B]wksp.BeginTrans ' all record set changes are buffered after this[/B]
[B]On Error GoTo roll0[/B]
strSQL = "SELECT * from tblWk"
Set rsWk = dbs.OpenRecordset(strSQL, dbOpenSnapshot)
i = rsWK(0) ' Explict Reference to the only field in the table (first)
strSQL = "UPDATE tblPMSales SET tblPMSales.i = tblPMInput.fldPMImportSalse "
strSQL = strSQL & "WHERE tblPMSales.fldContract = tblPMInput.fldContract"
DoCmd.RunSQL strSQL
[B]wksp.CommitTrans [/B]
GoTo finish_it
roll0:
If Err.Number = 3022 Then
On Error GoTo roll0
Resume check_next
End If
MsgBox Err.Number & " " & Err.Description
[B]wksp.Rollback ' cancel everything if unexpected error[/B]
finish_it:
Set rsWK = Nothing
Set dbs = Nothing
End Sub
However, I don't know where should I write this code. Should I write this into SQL statement, or as some VBA code? Currently my update query looks like this (See attachement).