SQL Action subroutine

NimbusSoftware

Registered User.
Local time
Today, 11:06
Joined
Feb 18, 2005
Messages
19
Is this a good strategy?
Code:
Public Function SQL_Action(strSQL As String, Optional fWS As Boolean = False) As Boolean
   On Error GoTo ErrorHandler
   Dim db As Database
   Dim sngStart As Single
   Dim wrk As Workspace

   Screen.MousePointer = 11
Try:
   Set db = CurrentDb
   If fWS Then Set wrk = DBEngine.Workspaces(0)
   If fWS Then wrk.BeginTrans
   db.Execute strSQL
   If fWS Then wrk.CommitTrans
   SQL_Action = True
   GoTo ExitHere

ErrorHandler:
   Select Case Err.Number
   Case 3051
      Err.Clear
      sngStart = Timer
      Do While Timer < sngStart + 5
          DoEvents
      Loop
      GoTo Try
   End Select
   If fWS Then wrk.Rollback
   MsgBox VBE.ActiveCodePane.CodeModule & ".SQL_Action" & vbNewLine & _
      "Error: " & Err.Number & vbNewLine & _
      Err.Description & vbNewLine

ExitHere:
   On Error Resume Next
   db.Close
   Set db = Nothing
   If fWS Then
      wrk.Close
      Set wrk = Nothing
   End If
   Screen.MousePointer = 0
End Function
 

Users who are viewing this thread

Back
Top Bottom