Hi all,
I am still new to VBA so I have been stratching my head all day.
I am trying to establish a connection with Table INFORCE in my database using ADO then loop through each record in one field (PLAN_CODE) to update value of another field (INITIAL_SAR)
So far, I got the code working if I decode them line by line. However, if I run them I got the following error "Runtime error -214735266 (8002000a) - Out of present range"
Below are my code:
Note: InitialSAR () is another function.
Thanks.
I am still new to VBA so I have been stratching my head all day.
I am trying to establish a connection with Table INFORCE in my database using ADO then loop through each record in one field (PLAN_CODE) to update value of another field (INITIAL_SAR)
So far, I got the code working if I decode them line by line. However, if I run them I got the following error "Runtime error -214735266 (8002000a) - Out of present range"
Below are my code:
Code:
Sub CalculateSAR()
' Open connection to INFORCE table
Dim myConnection As ADODB.Connection
Dim myRecordset As ADODB.Recordset
Set myConnection = CurrentProject.Connection
Set myRecordset = New ADODB.Recordset
myRecordset.Open Source:="INFORCE", _
ActiveConnection:=myConnection, _
CursorType:=adOpenDynamic, _
LockType:=adLockOptimistic
'Calculate SAR by looping through each record
Dim ArrayCol As Variant
Do Until myRecordset.EOF
ArrayCol = Array(myRecordset.Fields("PLAN_CODE"), myRecordset.Fields("INITIAL_SA"))
myRecordset!INITIAL_SAR = InitialSAR(ArrayCol)
myRecordset.MoveNext
Loop
myRecordset.Close
myConnection.Close
Set myConnection = Nothing
Set myRecordset = Nothing
End Sub
Note: InitialSAR () is another function.
Thanks.