Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2003
    Posts
    30

    Post Unanswered: Rollback Transaction in Access from VB

    Hello,

    Anybody got an idea on how I can perform a rollback when I call the following subroutine? I know I have to use BeginTrans and then I have to catch if there's an error at some point and then I must do a Rollback. I tried all the possible ways I though there would be but no success....

    Any suggestions would be welcome. Thanks


    ************************************************** ******


    'Procedure for Adding an Employee
    Public Sub InsertString(PathName As String)

    Dim strSQL As String

    strSQL = "INSERT INTO Employees (LastName, FirstName, Address," _ & "Telephone, DOB, SIN, DateEmployed, Department, EmployeeNumber," _ & "Email, Salary, Picture, Utilisateur, Notes, Ville, CodePostal, AutreNumero) VALUES ('" & FormEmployee.TextNom.Text & "', " _ & "'" & FormEmployee.TextPrenom.Text & "' , '" & FormEmployee.TextAdresse.Text & "','" & FormEmployee.TextTelephone.Text & "'," _ & "'" & FormEmployee.TextDateDeNaissance.Text & "','" & FormEmployee.TextAssuranceSociale.Text & "', " _ & "'" & FormEmployee.TextDateEmbauche.Text & "','" & FormEmployee.TextDepartement.Text & "', " _ & "'" & FormEmployee.TextNumeroEmploye.Text & "','" & FormEmployee.TextEmail.Text & "', " _ & "'" & FormEmployee.TextSalaire.Text & "','" & PathName & "','" & FormEmployee.CheckUtilisateur.Value & "', " _ & "'" & FormEmployee.RichTextBoxNotes & "','" & FormEmployee.TextVille.Text & "', " _ & "'" & FormEmployee.TextCodePostale.Text & "','" & FormEmployee.TextAutreNumero.Text & "')"

    Cn.Execute (strSQL)

    strSQL = "INSERT INTO Utilisateur (NumeroEmployee, NomUtilisateur, MotdePasse," _ & "NiveauUtilisateur) VALUES ('" & FormEmployee.TextNumeroEmploye.Text & "','" & FormEmployee.TextNomUtilisateur.Text & "'," _ & "'" & FormEmployee.TextMotDePasse.Text & "' , '" & FormEmployee.ComboNiveau.Text & "')"

    Cn.Execute (strSQL)

    End Sub

  2. #2
    Join Date
    Oct 2003
    Location
    Canada
    Posts
    574
    Are you linked to a non-access backend via ODBC? I could be wrong, but I thought this only works when you use an RDBMS as the back end. I had tried someting similar, but could not get it to work years ago in Access97 using Jet to connect to an Access97 file as the backend.

  3. #3
    Join Date
    Oct 2003
    Posts
    30
    I am linked to MS access XP and using an Adodc Connection. I managed to get it to work the code should be as follows:

    Public Sub InsertString(PathName As String)

    Dim strSQL As String

    On error goto errs:

    cn.begintrans

    strSQL = Some SQL STATEMENT

    Cn.Execute (strSQL)

    strSQL = Some more SQL STATEMENT

    Cn.Execute (strSQL)

    cn.committrans

    Exit sub

    errs:

    cn.rollbacktrans

    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •