Solved

Transaction Processing

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

746 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

13 Experts available now in Live!

Get 1:1 Help Now