【问题标题】:Transaction in Microsoft Acess, error 3034Microsoft Access 中的事务,错误 3034
【发布时间】:2014-08-14 02:24:04
【问题描述】:

我对 Access 2010 有疑问。

我使用事务将我的修改封装在一个表单中。此事务在 Form_Load() 子中启动。

Private Sub Form_Load()
  Debug.Print "Right here"
  DAO.DBEngine.Workspaces(0).BeginTrans
  Debug.Print "Here too"
...
End Sub

所以事务从第一行开始(之前没有运行其他任何东西,Debug.Print 只是在这里向您展示贯穿该行的代码)。 当我点击“保存”或“回滚”按钮时,我会运行如下代码:

Private Sub BtnSauvegarder_Click()
    DAO.DBEngine.Workspaces(0).CommitTrans dbForceOSFlush
    DoCmd.OpenForm "F_ListeDemande", acNormal, , , acFormEdit, acWindowNormal
    DoCmd.Close acForm, Me.name
End Sub

这就是我在保存或回滚代码中收到的错误 3034(类似)

但是,最奇怪的是:当我输入表单时,我的列表框有问题,里面什么都没有。如果我进入设计视图,什么都不做,然后进入普通视图,一切正常:列表框有他们应该有的记录集,事务工作正常。

这不是我第一次使用事务,我在其他表单上使用相同的方式没有任何问题。

那么我做错了什么?

编辑:
我制作了这段代码来输出 DAO.DBEngine 的当前状态,以防它有用。

Public Sub DebugDBEngine()
    Dim ws As Workspace
    Dim db As Database
    Dim p As Property

    For Each ws In DAO.DBEngine.Workspaces
        Debug.Print "Workspace : " & ws.name

        For Each p In ws.Properties
            On Error Resume Next
            Debug.Print "|  " & p.name & " = " & p.value
        Next

        For Each db In ws.Databases
            Debug.Print "|  Database : " & db.name

            For Each p In db.Properties
                On Error Resume Next
                Debug.Print "|  |  " & p.name & " = " & p.value
            Next
        Next
    Next
End Sub

所以我在交易开始后使用它,输出是这样的:

Workspace : #Default Workspace#
|  Name = #Default Workspace#
|  UserName = admin
|  IsolateODBCTrans = 0
|  Type = 2
|  Database : H:\Projet\05\15\10h28 - Suivi commande et fournisseur.accdb
|  |  Name = H:\Projet\05\15\10h28 - Suivi commande et fournisseur.accdb
|  |  Connect = 
|  |  Transactions = True
|  |  Updatable = True
|  |  CollatingOrder = 1036
|  |  QueryTimeout = 60
|  |  Version = 14.0
|  |  RecordsAffected = 0
|  |  ReplicaID = 
|  |  DesignMasterID = 
|  |  ANSI Query Mode = 0
|  |  Themed Form Controls = 1
|  |  AccessVersion = 09.50
|  |  NavPane Category = 0
|  |  UseMDIMode = 0
|  |  ShowDocumentTabs = True
|  |  Build = 24
|  |  HasOfflineLists = 70
|  |  Picture Property Storage Format = 0
|  |  CheckTruncatedNumFields = 1
|  |  ProjVer = 119
|  |  NavPane Closed = 0
|  |  NavPane Width = 226
|  |  NavPane View By = 0
|  |  NavPane Sort By = 1
|  |  Show Navigation Pane Search Bar = 0
|  |  WebDesignMode = 0
|  |  Theme Resource Name = Thème Office
|  |  Property Sheet Label Width = 2820
|  |  StartUpShowDBWindow = True
|  |  StartUpShowStatusBar = True
|  |  AllowShortcutMenus = True
|  |  AllowFullMenus = True
|  |  AllowBuiltInToolbars = True
|  |  AllowToolbarChanges = True
|  |  AllowSpecialKeys = True
|  |  UseAppIconForFrmRpt = False
|  |  AllowDatasheetSchema = True
|  |  DesignWithData = True
|  |  Show Values Limit = 1000
|  |  Show Values in Indexed = 1
|  |  Show Values in Non-Indexed = 1
|  |  Show Values in Remote = 0
|  |  Auto Compact = 0
|  |  Track Name AutoCorrect Info = 0
|  Database : H:\Projet\05\15\10h28 - Suivi commande et fournisseur.accdb
|  |(same things as above, it is the same database)

因此,同一个数据库打开了两次。我验证:在事务正确运行的地方,只有一个 DB 处于打开状态。

EDIT2:
我用这个调试再次测试进入正常视图,然后设计,然后正常。第一次,我得到了上面的输出。第二次,没有第二个相同的数据库也是一样的,只有一个数据库。
所以现在,我确定问题是它们打开了两个数据库。我所要找到的是为什么它打开两次相同的数据库。

【问题讨论】:

    标签: vba transactions ms-access-2010


    【解决方案1】:

    经过艰苦的搜索,我可能找到了问题所在。
    在设计视图中,我为列表框设置了一些查询来填充它们。它使用一个数据库来做到这一点。
    在我的 VBA 代码中,我使用 Recordset 来填充列表框。他们使用另一个数据库,即使它是相同的。
    所以我的解决方案很简单:我没有在设计视图中定义行源,所以只有 VBA 会填充列表框。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多