Dale Fye
asked on
Determine whether an ADO Execute method was successful or raised an error in VBScript
Background: Win XP, Access 2003 - due to legacy controls and client not ready to upgrade (go figure)
I have a VB script process which runs every 1/2 hour (from Windows Task Scheduler) to download data from an FTP site and write data to the Access database. Lately, the client has experienced issues with some records not getting written to the Access database properly. Yet I'm getting no indication that the ADO operation failed.
The code that writes the data to the Access database looks something like:
strSQL = INSERT INTO myTable (Field1, Field2, Field3) Values (1, 2, 3)
objConn.Execute strsql
where objConn has previously been defined.
I don't currently have any error handling in this process. Is there a way for me to determine whether the Execute method failed (raised an error), without creating a recordset to check for the value of the key field in this insert process?
I have a VB script process which runs every 1/2 hour (from Windows Task Scheduler) to download data from an FTP site and write data to the Access database. Lately, the client has experienced issues with some records not getting written to the Access database properly. Yet I'm getting no indication that the ADO operation failed.
The code that writes the data to the Access database looks something like:
strSQL = INSERT INTO myTable (Field1, Field2, Field3) Values (1, 2, 3)
objConn.Execute strsql
where objConn has previously been defined.
I don't currently have any error handling in this process. Is there a way for me to determine whether the Execute method failed (raised an error), without creating a recordset to check for the value of the key field in this insert process?
ASKER
@ste5an,
Working on it, but I'm getting a runtime error in the VBScript file (attached) when attempting to write to the Access file (also attached). You will obviously need to change the path to the Access file.
The error I'm getting is 424 - Object Required2019-08-23_VBScript_Error_Handling.txt
VBScript_Test.accdb
Working on it, but I'm getting a runtime error in the VBScript file (attached) when attempting to write to the Access file (also attached). You will obviously need to change the path to the Access file.
The error I'm getting is 424 - Object Required2019-08-23_VBScript_Error_Handling.txt
VBScript_Test.accdb
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks!
Getting lines 37 and 40 reversed had a lot to do with not being able to diagnose the problem. Which explains why I was getting a "Connection opened successfully" message but the inserts all failed with no object.
On the clients computer (XP and A2003) that connection string works for the code that is already in place, but I need to add some error handling to that code.
The script worked great on my computer (Win7, O2007) using the Ace provider, once I made those changes.
Getting lines 37 and 40 reversed had a lot to do with not being able to diagnose the problem. Which explains why I was getting a "Connection opened successfully" message but the inserts all failed with no object.
On the clients computer (XP and A2003) that connection string works for the code that is already in place, but I need to add some error handling to that code.
The script worked great on my computer (Win7, O2007) using the Ace provider, once I made those changes.
Open in new window
You need to clear the error object first, then call the method you want to test for errors. After this you evaluate the error object.For using this with ADODB connections, you must get the connection to return an error, thus use the dbFailOnError option. E.g.
Open in new window
Thus as encapsulated method:Open in new window
Depending on the kind of processing, I used sometimes Access itself as processor. Implement the logic in a separate Access database and start it (scheduled) with the /x PublicSubToInvoke parameter. Then you can do it in VBA.