Rollback doesn't work!

F

Fernando Castillo

Hi, i have a problem, I have a transaction that doesn't work, when
the msgbox pop up and I click "No", the rollback doesnt work and save
the changes made by the querys.

This is the code

Private Sub greg_Click()
On Error GoTo Err_greg_Click
DoCmd.SetWarnings False
Dim wrkCurrent As DAO.Workspace
Dim dbcondominio As DAO.Database
Dim Montopago, Abono, Dinicial As Long
Dim rs As DAO.Recordset

Set wrkCurrent = DBEngine.Workspaces(0)
Set dbcondominio = CurrentDb
Set rs = Form_DeudaActivaxCasa.RecordsetClone ' This recorset have the
transacction in False

wrkCurrent.BeginTrans

DoCmd.RunCommand acCmdSaveRecord

If rs.EOF = False Then
Abono = Form_DeudaActivaxCasa.Texto14
Montopago = Form_Ingreso_PagosAbonos.Monto
rs.MoveFirst
While rs.EOF = False
Dinicial = rs.Fields("SumaDePaab_Pago")
If Dinicial - (Abono + Montopago) <= 0 Then
DoCmd.OpenQuery "pagoautomatico", acNormal, acEdit
Montopago = (Abono + Montopago) - Dinicial
Abono = 0
' Verifica si existe atraso en el pago
If DateDiff("d", rs.Fields("Paab_Faplica"),
Form_Ingreso_PagosAbonos.Paab_Faplica) > 0 Then
Form_Ingreso_PagosAbonos.montomo = Dinicial
Form_Ingreso_PagosAbonos.codmo = rs.Fields("Paab_Codigo")
DoCmd.OpenQuery "Inserta_Mora", acViewNormal, acEdit
Form_Ingreso_PagosAbonos.montomo = ""
Form_Ingreso_PagosAbonos.codmo = ""
End If
rs.MoveNext
Else
rs.MoveLast
rs.MoveNext
End If
Wend
rs.MoveFirst
End If

DoCmd.OpenQuery "Inserta_ReciboPago", acNormal, acEdit
DoCmd.OpenQuery "Actupago_Casa", acNormal, acEdit
DoCmd.SetWarnings True

If MsgBox("¿Desea insertar el pago?", vbQuestion + vbYesNo) = vbYes
Then
wrkCurrent.CommitTrans
Else
wrkCurrent.Rollback
End If

rs.Close
' dbcondominio.Close
wrkCurrent.Close
Set rs = Nothing
' Set dbcondominio = Nothing
Set wrkCurrent = Nothing
Exit_greg_Click:
Exit Sub

Err_greg_Click:
MsgBox "Error #: " & Err.Number & vbCrLf & vbCrLf & Err.Description
'MsgBox Err.Description
Resume Exit_greg_Click

End Sub

This windows is a Form/Subform.
Form: Form_Ingreso_PagosAbonos
Subform: Form_DeudaActivaxCasa

I commented the end because when I insert a new record in the form
crashes because the database is closed

Sorry for my english.
Thanks in advance
Fernando
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top