Solved

COMMIT TRANS WITH ADO

Posted on 1998-10-14
4
518 Views
Last Modified: 2013-12-25
I'm using ADO 2.0 to connect to an ACCESS 97 database through an ODBC DSN.

I'm using the default provider: "MSDASQL"

Once connected, I used the following code:

conADO.BeginTrans
for nInd = 1 to 10
  rstADO.addnew
  ...
  rstADO.update
next
conADO.CommitTrans

I get the error "Operation invalid at this time." at conADO.begintrans.

WHY ?

Without begintrans and committrans, everything is working fine.
0
Comment
Question by:mxclouti
  • 3
4 Comments
 
LVL 3

Accepted Solution

by:
vmano earned 90 total points
ID: 1496946
try this:
move the line conADO.BeginTrans before you open the recordset.
and move the line conADO.CommitTrans  before you close the recordset.your code should look someting like this:

conADO.BeginTrans
Set rstADO = .....

for nInd = 1 to 10
  rstADO.addnew
  ...
  rstADO.update
next

rstADO.Close
conADO.CommitTrans  

let me know if this helps
vmao



0
 
LVL 3

Expert Comment

by:vmano
ID: 1496947
there is a correction in the line
"move the line conADO.CommitTrans before you close the recordset"

it should be
"move the line conADO.CommitTrans after you close the recordset"

sorry for the confusion.

vmano
0
 

Author Comment

by:mxclouti
ID: 1496948
Thanks. It's working. That was so simple.

Instead of the default provider (MSDASQL) I've tried to used the provider (Microsoft.JET.OLEDB.3.51):

conADO.ConnectionTimeout = glTimeOut
conADO.Provider = "Microsoft.JET.OLEDB.3.51"
conADO.Properties("user id") = "mxclouti"
conADO.Properties("password") = "nosmoke"
conADO.Properties("data source") = gsMDB
conADO.Properties("Jet OLEDB:System database") = gsMDW
conADO.Open
   
and I get the error "-2147467259 Unspecified error" at conADO.Open

If you can answer that for me or else I'll ask this question to all experts and accept your answer.

Thanks.
0
 
LVL 3

Expert Comment

by:vmano
ID: 1496949
I am not sure of the error number. I never tried like what you did. here is an alternative to what you are doing.

Dim Con as String

Con = "Driver={....}; Dbq=...;DefaultDir=...;Uid=...;Pwd=...;"

conADO.ConnectionString = Con
conADO.Open
..
conADO.Close
conADO.ConnectionString = ""

let me know if this helps
vmano



0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

821 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