Jump to content
Sign in to follow this  
Grax

Access DB Insert Help

Recommended Posts

Grax

I'm trying to insert some data into an access database with the code below and get an error:

==> The requested action with this object has failed.:

$oRec.Open("INSERT INTO CallRecord (CallRecord_AlarmNumber) VALUES (2)",$oADO)

$oRec.Open("INSERT INTO CallRecord (CallRecord_AlarmNumber) VALUES (2)",$oADO)^ ERROR

Ideas? This is my first attempt at inserting data into a DB, so I could be doing it totally wrong.

Thanks in Advance

$oADO = _dbOpen($Database)
$oRec = _dbOpenRecordset()

$oRec.Open("INSERT INTO CallRecord (CallRecord_AlarmNumber) VALUES (2)",$oADO)
            
$oRec.Close
$oADO.Close()

Share this post


Link to post
Share on other sites
Misha

$oADO = _dbOpen($Database)
$oRec = _dbOpenRecordset()

$oRec.Open("SELECT * FROM CallRecord",$oADO)
$oRec.Addnew
$oRec("CallRecord_AlarmNumber") = '2'
$oRec.Close
$oADO.Close()

I don't know the functions or how they work in autoit since I only used db access with vb6 so the code might not be correct but you get the overall idea.

Also, it could be a problem with your connection

Edited by Misha

Share this post


Link to post
Share on other sites
Grax

$oADO = _dbOpen($Database)
$oRec = _dbOpenRecordset()

$oRec.Open("SELECT * FROM CallRecord",$oADO)
$oRec.Addnew
$oRec("CallRecord_AlarmNumber") = '2'
$oRec.Close
$oADO.Close()

I don't know the functions or how they work in autoit since I only used db access with vb6 so the code might not be correct but you get the overall idea.

Also, it could be a problem with your connection

Tried this and now get the error:

==> The requested action with this object has failed.:

$oRec.AddNew

$oRec.AddNew^ ERROR

I did make sure I had the db closed within Access. I'm able to read from the db without problem.

Andrew

Share this post


Link to post
Share on other sites
Grax

It there anywhere that explains the .Open/.AddNew functions and others for an access db? Everthing I've done I've scavenged from other code examples.

Share this post


Link to post
Share on other sites
Misha

OPEN - Opens a record set in 4 different ways: Select - shows you a list of items if nothing is specefied it just shows you the list of items; DELETE/INSERT obvious and update, the line you input in the open is a sql line that specefies what you want.

Addnew - adds a new record with empty fields.

Error came because I used addnew in a wrong way

_AccessConnectConn($s_dbname, $o_adoCon, $i_adoMDB, $USRName, $PWD);replace things here
$o_adoRs = ObjCreate("ADODB.Recordset")

$oRec.Open("SELECT * FROM CallRecord",$o_adoCon)
$oRec.Addnew
$oRec.Fields("CallRecord_AlarmNumber").value = '2'
$oRed.Update
$oRec.Close
$oADO.Close()

Fixed it abit *warning might not work since my skills are shit.

Edited by Misha

Share this post


Link to post
Share on other sites
Grax

OPEN - Opens a record set in 4 different ways: Select - shows you a list of items if nothing is specefied it just shows you the list of items; DELETE/INSERT obvious and update, the line you input in the open is a sql line that specefies what you want.

Addnew - adds a new record with empty fields.

Error came because I used addnew in a wrong way

_AccessConnectConn($s_dbname, $o_adoCon, $i_adoMDB, $USRName, $PWD);replace things here
$o_adoRs = ObjCreate("ADODB.Recordset")

$oRec.Open("SELECT * FROM CallRecord",$o_adoCon)
$oRec.Addnew
$oRec.Fields("CallRecord_AlarmNumber").value = '2'
$oRed.Update
$oRec.Close
$oADO.Close()

Fixed it abit *warning might not work since my skills are shit.

Didn't work same error...

Share this post


Link to post
Share on other sites
Grax

I figured out why my first attempt didn't work. It was because I had some required fields in the db. I corrected that and it now does the INSERT.

However I get an error:

==> The requested action with this object has failed.:

$oRec.Close

$oRec.Close^ ERROR

I'm still missing something. :)

Share this post


Link to post
Share on other sites
Misha

add $oRec.update

Share this post


Link to post
Share on other sites
Grax

add $oRec.update

Same error, just on the .Update now...

==> The requested action with this object has failed.:

$oRec.Update

$oRec.Update^ ERROR

Share this post


Link to post
Share on other sites
amokoura

Try using the same commands in Access GUI and Access VBA and see if it gives some more informative errors than FAILED :)

Share this post


Link to post
Share on other sites
Grax

If I remove the $oRec.Close and $oRec.Update it works without problems. Still have to close the db connection though.

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
Sign in to follow this  

×