Grax Posted May 21, 2008 Posted May 21, 2008 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()
Misha Posted May 21, 2008 Posted May 21, 2008 (edited) $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 May 21, 2008 by Misha
Grax Posted May 21, 2008 Author Posted May 21, 2008 $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 connectionTried this and now get the error:==> The requested action with this object has failed.:$oRec.AddNew $oRec.AddNew^ ERRORI did make sure I had the db closed within Access. I'm able to read from the db without problem.Andrew
Grax Posted May 21, 2008 Author Posted May 21, 2008 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.
Misha Posted May 21, 2008 Posted May 21, 2008 (edited) 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 May 21, 2008 by Misha
Grax Posted May 21, 2008 Author Posted May 21, 2008 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...
Grax Posted May 21, 2008 Author Posted May 21, 2008 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.
Grax Posted May 21, 2008 Author Posted May 21, 2008 add $oRec.updateSame error, just on the .Update now...==> The requested action with this object has failed.:$oRec.Update $oRec.Update^ ERROR
amokoura Posted May 21, 2008 Posted May 21, 2008 Try using the same commands in Access GUI and Access VBA and see if it gives some more informative errors than FAILED
Grax Posted May 22, 2008 Author Posted May 22, 2008 If I remove the $oRec.Close and $oRec.Update it works without problems. Still have to close the db connection though.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now