View Single Post
Old 01-19-2013, 08:24 PM   PM User | #1
tequilasunsette
New to the CF scene

 
Join Date: Jan 2013
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
tequilasunsette is an unknown quantity at this point
Clear MS-Access Memory with Javascript before next query

I was having some issues with retrieving the SUM from a column in my access database and displaying the value in a html textbox.--This i was able to fix with the function below.

Issue: I've found that the below function works fine to retrieve the sum. But for some reason, if a value changes in my database, the SUM does not get updated when the function is called again.

Here is how i found it has something to do with the memory not getting refreshed/cleared in Access

I made a "copy" of my access DB, renamed it to something different, changed the values in the column im summing, and updated the code with the new DB path. once i did this, my textbox populated the correct sum. Again, if i changed values in this DB copy, the new sum would not refresh..

It appears that access is unable to clear the last query run and must be done before i run my SUM function. And this is something i'm clueless about writing in JS. hoping someone has encountered this before.

Here is the working function that retrieves the SUM from a column in my DB:

Code:
var adoconn = new ActiveXobject("ADODB.Connection");
adoconn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='database.mdb'");
var cmd = new ActiveXObject("ADODB.Command");
cmd.ActiveConnection = adoconn;
var adoRS = new ActiveXobject("ADODB.Recordset");
var strSQL = "Select SUM(database_column_name) As Total FROM tablename";
cmd.CommandText = strSQL;
adoRS = cmd.Execute();
textbox1.value = adoRS.Fields(0);
Thank you for reading this far. Desperately looking for some help
tequilasunsette is offline   Reply With Quote