Jump to content

v3.3.14.1 Obj Failed when no db.Value returned


Recommended Posts

Just upgraded to the new version

I have some problems with a couple databases getting record counts back from queries so I started just getting the value of a Primary Key ID and if > 0 then there were records returned.

With this new version, the script bombs when no record was returned.

 

Here is an example I put together.  The Table does not have any Text1 = 'ABC' so the Returned ID value was empty, but now I get the following error:

"H:\My Scripts\AutoIT-3\Database Stuff\Get Data from Access Database.au3" (14) : ==> The requested action with this object has failed.:
if .Fields("ID").Value > 0 Then
if .Fields("ID")^ ERROR

 

 

$sTargetDB = "C:\Temp\Database.accdb"

    $Conn = ObjCreate("ADODB.Connection")
    $Conn.open("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & $sTargetDB)
    $adoRs = ObjCreate ("ADODB.Recordset")
    $adoRs.CursorType = 2
    $adoRs.LockType = 3

    $sSQL = "Select * from TableName Where Text1 = 'ABC'"

    $adoRs.Open($sSQL, $Conn)
    If $adoRs.State = 1 Then
        With $adoRs
            if .Fields("ID").Value > 0 Then
                MsgBox(0, "Return 1", .Fields("Text1").Value)
                MsgBox(0, "Return 2", .Fields("Text2").Value)
            Else
                MsgBox(0, "", "Did not retrieve any data")
            EndIf
        EndWith
    Else
        MsgBox(0, "State Failed", "Connection State failed")
    EndIf
    $adoRs.Close
    $Conn.Close

 

Edited by BigDaddyO
Link to comment
Share on other sites

Unfortunately the way how COM errors are handled has changed. You now need to add a COM error handler to your script and check for errors.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...