I have a database that, among other things will calculate the score of a site based on attributes of that site and the weighting factors assigned to each attribute.
The db allows the user to change the weighting factors at will and re-calculate the score. I am having trouble with the syntax of ADO recordsets and I was hoping someone could set me straight.
Here is the code I have for a module:
So ... In the same table I have a field "FactBlue" which is the weighting factor used in the calculation (changable by the user), I have another field called dfltFactBlue, which holds the default value. What I want the Sub to accomplish is replace the value in the FactBlue field with the value in the dfltFactBlue field ---- for each record and save the table at the end of it (if rst.Close,etc does not do this??).
Thanks for your help.
DJ
The db allows the user to change the weighting factors at will and re-calculate the score. I am having trouble with the syntax of ADO recordsets and I was hoping someone could set me straight.
Here is the code I have for a module:
Code:
Public Sub HabValDefault(sTableName As String)
On Error GoTo ErrorHandler
Dim rst As ADODB.Recordset
Dim cnn As ADODB.Connection
Dim FactVar As Long
Dim FactDefault As Long
Set rst = New ADODB.Recordset
Set cnn = New ADODB.Connection
Set cnn = CurrentProject.Connection
rst.Open sTableName, cnn
With rst
Do While Not .EOF
FactDefault = rst![dfltFactBlue]
Set rst![FactBlue] = FactDefault
'Goto next record
.MoveNext
Loop
End With
'Close the Recordset and Connection Objects
rst.Close
cnn.Close
Set rst = Nothing
Set cnn = Nothing
Exit Sub
ErrorHandler:
Set rst = Nothing
Set cnn = Nothing
Err.Clear
End Sub
So ... In the same table I have a field "FactBlue" which is the weighting factor used in the calculation (changable by the user), I have another field called dfltFactBlue, which holds the default value. What I want the Sub to accomplish is replace the value in the FactBlue field with the value in the dfltFactBlue field ---- for each record and save the table at the end of it (if rst.Close,etc does not do this??).
Thanks for your help.
DJ