Solved

Transaction Processing

Posted on 1998-12-15
1
125 Views
Last Modified: 2010-05-03
Can I have a trasaction that spans multiple forms?  To do this, do I have to define Workspace and define and open the DB in a global module shared by all forms in my application?
0
Comment
Question by:baileys
1 Comment
 
LVL 3

Accepted Solution

by:
vbWhiz earned 100 total points
ID: 1450368
In a word, Yes Yes.

Unless you are using bound forms. I havn't ever used bound forms in VB so if you are that may make things a little more difficult.

If, however, you save information to the database using code then it is really quite simple to wrap data alterations in a transaction. The more difficult part is structuring your application in a way that makes it easy to understand what is going on or that seamlessly uses transactions behind the scenes to insure the data is being modified all at once.


This is some psuedo code (you probably don't want buttons to begin, commit, and cancel the transaction. This is just to illustrate how to use transactions in a form-based application using a public workspace variable.)


'[Code in the declarations section of a module]

Public WS as workspace
Public DB as database
Public TransactionInProcess AS Boolean

Public Sub Connect()

Set WS = DBEngine.CreateWorkspace("","Admin","")
Set DB= WS.OpenDatabase("C:\MyDB.mdb")

End Sub




'[Code in the header form]

Private Sub cmdBeginTrans_Click()

  IF TransactionInProcess Then Exit Sub

  WS.BeginTrans

End Sub

Private Sub CmdSave_Click()

'Save the info here using a recordset created from the public DB

End Sub


Private Sub cmdCommitTrans_Click()

  IF Not TransactionInProcess Then Exit Sub

  WS.CommitTrans

End Sub

Private Sub cmdCancelTrans_Click()

  IF Not TransactionInProcess Then Exit Sub

  WS.Rollback

End Sub



'[Code on a detail form]

Private Sub CmdSave_Click()

'Save the info using another recordset based on the public DB

End Sub


0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now