我在MS Access 2007中使用ODBC源到MySQL 5.6数据库时遇到问题。基本上,我正在插入一个“主”记录,然后在另一个表中插入“子”记录。但是,即使我明确地将它们回滚,也会提交记录。
该功能的简化版如下:
Dim ws As Workspace: Set ws = DBEngine.Workspaces(0)
Dim db As Database: Set db = CurrentDb
Dim NewID&
ws.BeginTrans
' insert the "master" record
s = "INSERT INTO ..."
db.Execute s
' get the new record ID using a passthrough query to MySQL
NewID = gfMySQL_GetNewID
' insert multiple "child" records, using the NewID
s = "INSERT INTO ..."
db.Execute s
If vbYes = MsgBox("Commit?", vbQuestion + vbYesNo) Then
ws.CommitTrans
Else
ws.Rollback
GoTo exit_handler
End If
这让我很难过,如果有人有建议我会非常感激!