Jump to content
BigDaddyO

v3.3.14.1 Obj Failed when no db.Value returned

Recommended Posts

BigDaddyO

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

hmm... I guess I have to have a signature...

Share this post


Link to post
Share on other sites
water

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 (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
BigDaddyO

grumble, grumble...  

ok, i'll add that.

Thanks for the info


hmm... I guess I have to have a signature...

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

×