Article ID: 146908
Article Last Modified on 7/15/2004
145757 : Ideas to Consider When Using Transactions
Private Sub Form_Load ()
Dim Starttime, Endtime
Dim db As Database
Dim t As RecordSet
Dim i As Integer
Dim tempName As String
Dim temphone As String
Set db = Workspace(0).OpenDatabase("c:\vb\BIBLIO.MDB") ' Uses a
' copy of BIBLIO.MDB.
Set t = db.OpenRecordSet("Publishers", dbOpenTable)
Starttime = Now
'BeginTrans ' Add this and CommitTrans (below) for greater speed.
For i = 1 To 100
tempName = "testname" & Str$(i) ' Make an arbitrary unique
' string.
tempPhone = Str$(i) ' Make arbitrary number.
t.AddNew ' AddNew clears copy buffer to prepare for new record.
t!PubID = 30 + i ' Set primary key to unique value.
t!Name = tempName ' Set Name field to unique value.
t!Telephone = tempPhone ' Set Telephone field to unique value.
t.Update ' Write the record to disk or to transaction buffer.
Next i
'CommitTrans ' Add this and BeginTrans (above) for greater speed.
Endtime = Now
MsgBox "Time required= " & Format(Endtime - Starttime, "hh:mm:ss")
t.Close
db.Close
End
End Sub
The above code adds 100 new records to the BIBLIO.MDB database file.
Add the records to a copy of BIBLIO.MDB instead of to the original.
Additional query words: kbVBp400 kbVBp500 kbVBp600 kbdse kbDSupport kbVBp
Keywords: kbhowto KB146908