home *** CD-ROM | disk | FTP | other *** search
-
- Private Sub cmdTest_Click()
-
- Dim Start, Finish, TotalTime 'Timer Variables
- Dim rstPublishers As DAO.Recordset 'Holds the recordset used by Option 2
- Dim strSQL As String 'Update string for Option 2
-
- 'With this timing example we just want to measure
- 'the update time. All connections and recordsets
- 'will be established prior to the timers starting.
-
- 'Open the recordset for Option 1
- If Option1.Value = True Then
- 'Open the Recordset object for the update
- 'Only retrieve records from the state of CA
- '
- Set rstPublishers = _
- gdbBiblio.OpenRecordset("SELECT * FROM Publishers", _
- dbOpenDynaset)
- Else
- strSQL = "UPDATE Publishers Set Comments = "
- strSQL = strSQL & "'Buy VB Development Unleashed'"
-
- End If
-
- 'Begin the timing operation
- If Option1.Value = True Then
- Start = Timer
-
- 'DAO Update Timing Test - Note this is POOR
- 'Performance - DO NOT UPDATE Several DATABASE
- 'Records this way!
- With rstPublishers
- While Not .BOF And Not .EOF
- 'Update the recordset comment field
- .Edit rstPublishers("Comments") = "Buy VB Development Unleashed"
- .Update
-
- 'Move to the next record
- .MoveNext
- Wend
- End With
-
- 'End of Code time test
- Finish = Timer
-
- 'Clean up
- rstPublishers.Close
- Set rstPublishers = Nothing
- Else
- 'Option 2 selected - SQL Updates and Transactions
- Start = Timer
-
- 'Note: The following code performs much faster!
- 'When updating, adding or deleting records using DAO
- 'use transactions to speed up the operation.
- 'When modifying or deleting a large number of records
- 'use SQL statements
- gwksTest.BeginTrans
- gdbBiblio.Execute strSQL
- gwksTest.CommitTrans
- 'End of Code time test
- Finish = Timer
-
- End If
-
- TotalTime = Finish - Start ' Calculate total time.
-
- '
- 'Set up display results
- '
- If Option1.Value = True Then
- 'Option 1
- lblOpt1.Caption = "Total time to execute " & _
- Option1.Caption & ": " & _
- TotalTime
- Else
- 'Option 2
- lblOpt2.Caption = "Total time to execute " & _
- Option2.Caption & ": " & _
- TotalTime
- End If
-
- End Sub
-