"out of present range" Error

clover_vn

New Member
Joined
Oct 6, 2008
Messages
11
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:

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.
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Forum statistics

Threads
1,214,985
Messages
6,122,602
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top