[SIZE="1"][FONT="Verdana"]Sub TransactionTimings()
Const MAX_LOOP = 5000&
Const TABLE_NAME = "tDate"
Dim dbs As DAO.Database
Dim wrk As DAO.Workspace
Dim time As Single
'get or clear a table
GetTable CurrentDb, TABLE_NAME
Debug.Print "Inserting " & MAX_LOOP & " records, twice..."
'start timer for non-transaction enabled database
time = Timer
'get current db
Set dbs = CurrentDb
'insert a bunch of dates
InsertDates dbs, MAX_LOOP, TABLE_NAME
'and print how long it took
Debug.Print "No Transaction: " & Timer - time & "sec"
'start the timer
time = Timer
'get the default workspace
Set wrk = DBEngine.Workspaces(0)
'begin trans against the default workspace
wrk.BeginTrans
'get CurrentDB from transaction enabled default workspace
Set dbs = CurrentDb
'run a bunch of inserts
InsertDates dbs, MAX_LOOP, TABLE_NAME
'commit the transaction
wrk.CommitTrans
'and how long did that take
Debug.Print "Transaction : " & Timer - time & "sec"
'and prove all the records were actually added
Debug.Print TABLE_NAME & " contains " & DCount("*", TABLE_NAME) & " records."
Debug.Print
End Sub
Sub GetTable(dbs As DAO.Database, tableName As String)
On Error GoTo handler
'create the table
dbs.Execute _
"CREATE TABLE " & tableName & " " & _
"(id COUNTER CONSTRAINT PK_ID PRIMARY KEY, " & _
"[mydate] date)"
Exit Sub
handler:
If Err = 3010 Then 'table already exists
'or if it already exists, delete any records
dbs.Execute "DELETE FROM " & tableName
End If
End Sub
Sub InsertDates(dbs As DAO.Database, count As Integer, tableName As String)
Dim i As Integer
'inserts multiple records into the table
For i = 1 To count
dbs.Execute _
"INSERT INTO " & tableName & " " & _
"( mydate ) " & _
"VALUES " & _
"( #" & Now() & "# );"
Next
End Sub[/FONT][/SIZE]