Solved

Transaction Processing

Posted on 1998-12-15
1
127 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

785 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