DAOトランザクション処理
Private Sub RunSQL()
Dim strSQL As String
Dim DB As DAO.Database
Dim WSP As Workspace
On Error GoTo Err_order
Set WSP = DBEngine.Workspaces(0)
Set DB = CurrentDb
'トランザクション処理開始
WSP.BeginTrans
DB.Execute strSQL
If DB.RecordsAffected = 0 Then
'ロールバック処理
WSP.Rollback
Else
'トランザクション処理終了
WSP.CommitTrans
End If
Exit_order:
'WSP.Close は不要
Set DB = Nothing
Set WSP = Nothing
Exit Sub
Err_order:
MsgBox Err.Description
'トランザクション処理終了(処理をなかったことにする)
WSP.Rollback
Resume Exit_order
End Sub