Article ID: 117167
Article Last Modified on 5/6/2003
' ****************************************************************
' Declarations section of the module
' ****************************************************************
Option Compare Database
Option Explicit
' ****************************************************************
' The RightCount() function creates a dynaset based on the
' Employees table, prints the table's record count, starts a new
' transaction, adds a record, rolls back the transaction, and then
' prints the dynaset's record count.
' ****************************************************************
Function RightCount ()
Dim db As Database
Dim MyDyna As Dynaset
Set db = CurrentDB()
Set MyDyna = db.CreateDynaset("Employees")
MyDyna.MoveLast
Debug.Print "BEFORE Transaction: Employee Record Count = " & _
MyDyna.recordcount
BeginTrans
MyDyna.AddNew
MyDyna![Last Name] = "Doe"
MyDyna![First Name] = "John"
MyDyna.Update
Rollback
MyDyna.Close
Set MyDyna = db.CreateDynaset("Employees")
MyDyna.MoveLast
Debug.Print "AFTER Transaction: Employee Record Count = " & _
MyDyna.recordcount
MyDyna.Close
End Function
?RightCount()
' ****************************************************************
' Declarations section of the module
' ****************************************************************
Option Compare Database
Option Explicit
' ****************************************************************
' The WrongCount() function opens the Employees table, prints the
' record count, starts a new transaction, adds a record, rolls
' back the transaction, and then prints the table's record count.
' ****************************************************************
Function WrongCount ()
Dim db As Database
Dim MyTable As Table
Set db = CurrentDB()
Set MyTable = db.OpenTable("Employees")
MyTable.MoveLast
Debug.Print "BEFORE: Employee Record Count = " & _
MyTable.RecordCount
BeginTrans
MyTable.AddNew
MyTable![Last Name] = "Doe"
MyTable![First Name] = "John"
MyTable.Update
Rollback
MyTable.Close
Set MyTable = db.OpenTable("Employees")
MyTable.MoveLast
Debug.Print "AFTER: Employee Record Count = " & _
MyTable.RecordCount
MyTable.Close
End Function
?WrongCount()
Keywords: kbprogramming kbprb KB117167