I have the code below, that writes data into a table. It takes 37 seconds to create 1000 records. Please can anyone suggest how I can modify the code to improve the time it takes to create those records? Many thanks
Code:
Private Sub cmdStartDateTest_Click()
Dim start As String
Dim myDate As Date
Dim finish As String
Dim loopCount As Integer
txtDate = ""
MsgBox "Starting Audit loop..."
loopCount = 1000
Do While (loopCount > 0)
start = Time
myDate = Date
finish = Time
'txtDate.SetFocus
txtDate = myDate
' MsgBox "within Audit loop..."
insertRecord start, finish
loopCount = loopCount - 1
Loop
MsgBox "Audit loop finished!"
End Sub
Private Sub insertRecord(start As String, finish As String)
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Set cnn = CurrentProject.Connection
rst.Open "tblAuditTrail", cnn, adOpenDynamic, adLockPessimistic
'rst.OpenRecordset
rst.AddNew
rst!dateUpdate = start
rst!Record = "Amjad,Ali Movement 16/02/2011 11:49:05 HistoryDate=16/02/2011 HistoryTime=11:49 HistoryNotes=Test test LocationID=4 Dunstable Road CrimeID=Adbuction"
rst.Update
rst.Close
Set rst = Nothing
End Sub