Read and write to an access database using Javascript

First, make sure that ‘/\’ and ‘\’ (in connection string) is just a typo in SO.

Second, here is a version of Delete command:

function DeleteRecord() {
var adoConn = new ActiveXObject("ADODB.Connection");
var adoCmd = new ActiveXObject("ADODB.Command");

adoConn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="\\dbName.mdb"");
adoCmd.ActiveConnection = adoConn;
adoCmd.CommandText = "Delete * From tblName Where FieldName="Quentin"";
adoCmd.Execute();

adoConn.Close();
}

And, Edit command (without looping -> updates all [matching] records):

function EditRecord() {
var adoConn = new ActiveXObject("ADODB.Connection");
var adoCmd = new ActiveXObject("ADODB.Command");

adoConn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="\\dbName.mdb"");
adoCmd.ActiveConnection = adoConn;
adoCmd.CommandText = "Update tblName Set FieldName="New Value" Where FieldName="Quentin"";
adoCmd.Execute();

adoConn.Close();
}  

Please note, I have not tested this (do not have Access right now), so there might be some
syntax bugs…

Hope it works and helps.

Leave a Comment