Jump to content

Access DB Insert Help


Recommended Posts

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()
Link to comment
Share on other sites

$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
Link to comment
Share on other sites

$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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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...
Link to comment
Share on other sites

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. :)

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...