Solved

Begin Trans  - Rollback - Commit Trans

Posted on 2000-03-27
6
1,333 Views
Last Modified: 2012-06-27
Can someone please modify my coding, so that enable Begin Trans  - Rollback - Commit Trans.

=====================================================
Private Sub abAdd_Click()
On Error GoTo sysError
    Dim sCriteria As String
    Dim rst As ADODB.Recordset
   
    'Begin Trans here??
    SetupRes rst
    rst.Open ("SELECT * FROM addBook")
    rst.AddNew
        rst!abName = addressBook.abName.Text
        rst!abBirthday = addressBook.abBirthday.Text
        rst!abGender = addressBook.abGender.Text
        rst!abHomeAdd = Trim(addressBook.abHomeAdd.Text)
    rst.Update
    'Commit Trans here
    rst.Close    'close database
    Exit Sub
sysError:
    'Rollback here
    msgBox  Err.Number & " : " & Err.Description _
            & Chr(10) & Chr(10) & "Sub: abAdd_Click()"
    Unload Me
End Sub

Public Sub SetupRes(ByRef vRes As ADODB.Recordset)
    Set vRes = New ADODB.Recordset
    Set vRes.ActiveConnection = con
    vRes.CursorLocation = adUseClient
    vRes.LockType = adLockOptimistic
    vRes.CursorType = adOpenDynamic
    vRes.CursorLocation = adUseClient
End Sub
0
Comment
Question by:pkimk
6 Comments
 

Expert Comment

by:pinshah
ID: 2663109
Where are u getting the connection from? If Con is a Connection object and is a global variable then

Just do

Con.BeginTrans

Ur Recordset code


Con.CommitTrans


ErrorLabel:

cON.RollBackTrans
0
 
LVL 2

Expert Comment

by:sbmc
ID: 2663123
Hello pkimk

The Begintrans,CommitTrans and Rollback methods apply to the connection object. Code is as follows.

Hope it helps



Private Sub abAdd_Click()
On Error GoTo sysError
    Dim sCriteria As String
    Dim rst As ADODB.Recordset
     
    'Begin Trans here??
    SetupRes rst
    rst.Open ("SELECT * FROM addBook")
    con.BeginTrans
    rst.AddNew
        rst!abName = addressBook.abName.Text
        rst!abBirthday = addressBook.abBirthday.Text
        rst!abGender = addressBook.abGender.Text
        rst!abHomeAdd = Trim(addressBook.abHomeAdd.Text)
    rst.Update
    'Commit Trans here
    con.CommitTrans
    rst.Close    'close database
    Exit Sub
sysError:
    'Rollback here
    con.Rollback
    msgBox  Err.Number & " : " & Err.Description _
            & Chr(10) & Chr(10) & "Sub: abAdd_Click()"
    Unload Me
End Sub

Public Sub SetupRes(ByRef vRes As ADODB.Recordset)
    Set vRes = New ADODB.Recordset
    Set vRes.ActiveConnection = con
    vRes.CursorLocation = adUseClient
    vRes.LockType = adLockOptimistic
    vRes.CursorType = adOpenDynamic
    vRes.CursorLocation = adUseClient
End Sub
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2663134
You are putting the transaction codes in the right place, just need to apply whatever object it is youre using to it.
0
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.

 
LVL 2

Accepted Solution

by:
sbmc earned 50 total points
ID: 2663174
Hello pkimk

The Begintrans,CommitTrans and Rollback methods apply to the connection object. Code is as follows.

Hope it helps



Private Sub abAdd_Click()
On Error GoTo sysError
    Dim sCriteria As String
    Dim rst As ADODB.Recordset
     
    'Begin Trans here??
    SetupRes rst
    rst.Open ("SELECT * FROM addBook")
    con.BeginTrans
    rst.AddNew
        rst!abName = addressBook.abName.Text
        rst!abBirthday = addressBook.abBirthday.Text
        rst!abGender = addressBook.abGender.Text
        rst!abHomeAdd = Trim(addressBook.abHomeAdd.Text)
    rst.Update
    'Commit Trans here
    con.CommitTrans
    rst.Close    'close database
    Exit Sub
sysError:
    'Rollback here
    con.Rollback
    msgBox  Err.Number & " : " & Err.Description _
            & Chr(10) & Chr(10) & "Sub: abAdd_Click()"
    Unload Me
End Sub

Public Sub SetupRes(ByRef vRes As ADODB.Recordset)
    Set vRes = New ADODB.Recordset
    Set vRes.ActiveConnection = con
    vRes.CursorLocation = adUseClient
    vRes.LockType = adLockOptimistic
    vRes.CursorType = adOpenDynamic
    vRes.CursorLocation = adUseClient
End Sub
0
 
LVL 1

Expert Comment

by:simonstre
ID: 2665059
u also could use the batch
(adlockbath) instead of adlockoptimistic.
Think it's faster, but i'm not sure.
0
 

Author Comment

by:pkimk
ID: 2667424
con define as ...
Public con As ADODB.Connection

Many Thanks.
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

Suggested Solutions

Title # Comments Views Activity
vb6 connector to mongodb 2 82
Prevent checkbox click event occur while editing it in vb6 8 44
Visual Studio 2005 text editor 10 38
Spell Check in VB6 13 112
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

776 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