VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 4  'RequiresNewTransaction
END
Attribute VB_Name = "Test"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Public Function RollBack(ByVal strConn As String, _
                         ByVal blnFail As Boolean, _
                         ByVal strSQl As String, _
                         ByVal intRepeat As Integer) As Boolean
                         
    On Error GoTo ErrorHandler
    Dim objCTX As ObjectContext
    Dim con As ADODB.Connection
    Dim x As Integer

    Set objCTX = GetObjectContext()
    
    Set con = New ADODB.Connection
    con.Open (strConn)

    For x = 1 To intRepeat  ' repeat SQL
        
        If objCTX.IsInTransaction = False Then
            Err.Raise vbObjectError + 100, "Rollback", " Not In MTS Transaction - Test Voided Before Connection Opened"
        End If
        
        ' Execute the SQL statement
        con.Execute strSQl, , adCmdText
    Next
        
    con.Close
    Set con = Nothing

    If blnFail = True Then
        objCTX.SetAbort
        RollBack = True
    Else
        objCTX.SetComplete
        RollBack = False
    End If

    Set objCTX = Nothing

    Exit Function

ErrorHandler:
    If Err <> vbObjectError + 100 Then
        MsgBox Err.Number & ": " & Err.Description
        objCTX.SetAbort
        RollBack = False
    
        Set objCTX = Nothing
        Set con = Nothing
    End If

End Function

