Ok, I'm about to tear my hair out. I'm trying to add a record to an Access database using the following code:
Code:
var uAns = document.getElementById("uChoices");
//..........connection string............//
yrAnswer-=0
yScore-=0
var iStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\userRecs.mdb";
var adOpenKeyset = 1;
var adLockOptimistic = 3;
var adCmdText = 1;
var adUseClient = 3;
//..........................................//
//.............ActiveX Setup............//
var cObj = new ActiveXObject("ADODB.Connection");
var recSet = new ActiveXObject("ADODB.Recordset");
recSet.CursorLocation = adUseClient;
cObj.CursorLocation = adUseClient;
cObj.Open(iStr)
var grStr = "SELECT * FROM " + uId
recSet.Open(grStr,cObj,adOpenKeyset,adLockOptimistic,adCmdText)
recSet.AddNew;
recSet.Fields("Question_Number").value = 0
recSet.Fields("Your_Answer").value = yrAnswer
recSet.Fields("Score_for_This_Question").value = yScore
recSet.Fields("Possible_Score_For_This_Question").value = availScore.value
recSet.Update;
recSet.close
Now this code appears to work fine until it gets to this line:
Code:
recSet.Fields("Your_Answer").value = yrAnswer
At this point I get this error: "Multiple Step operation generated errors. Check all values". After lots of Googling I found out that it usually means you're trying to add a value with an invalid data type into the field. So at this point I googled again and found something on DevNet which says you can use rs.DefinedSize to set the size of the field. But not until the value of the field has been set and not until after the rs.Update method has been used to update the database. So I tried this. I then got an error saying that I couldn't use DefinedSize method while the connection was open. So I closed it. It still didn't work because I'm trying to add a value that is too large to a field in the table (the yrAnswer variable). So this is the problem:
1. I can't add the value to the field first because the value is too large
2. I can't change the DefinedSize property of the field until AFTER the value attribute of the Field object has been set and the Update method called.
How do I get the value in, or set the field size, and in which order? Google has been semi helpful, but I can't find much on Javascript and ADO.
All help appreciated.
Joe