BigDaddyO

v3.3.14.1 Obj Failed when no db.Value returned

3 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

grumble, grumble...  

ok, i'll add that.

Thanks for the info


Share this post


Link to post
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