質問

I have an issue with Access 2010.

I use transaction to encapsulate my modification in a form. This transaction is started in the Form_Load() sub.

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

So the transaction is started at the very first line (nothing else is running before, the Debug.Print are just here to show you the code run through the line). When I click on the button "save" or "rollback", I run some code like this :

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

And that's here I got the error 3034, both in save or rollback code (which are similar)

BUT, the weirdest thing is here : when I entered the form, my Listbox are bugy, nothing are inside. If I entered in Design view, do nothing and then entered in the Normal view, everything run right : Listbox have the Recordset they are supposed to have and the transaction work fine.

This is not the first time I use transaction, I used the same way on other forms without any problem.

So what I am doing wrong ?

EDIT :
I made this code to output the current state of DAO.DBEngine, in case it is useful.

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

So I use it just after the beginning of the transaction and the output is this :

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)

So, the same DB is open twice. I verify : where the transactions are correctly runing, only one DB is open.

EDIT2 :
I tested again with this debug to enter in normal view, then design and then normal. The first time, I've got the output just above. The second time, it is the same without the second same database, there is juste one DB.
So now, I'm sure the problem is they are two databases opened. All I have to find is WHY it open twice the same DB.

役に立ちましたか?

解決

With hard searching, I probably found the problem.
In Design view, I set to Listboxes some query to fill them. It use one database to do it.
In my VBA code, I use Recordset to fill the Listboxes. And they use another database, even if it is the same.
So my solution is simple : I don't define the rowsource in Design view, so only the VBA will fill the Listboxes.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top