Hi,
I am new to ACCESS and need help with this.
I have a table named SIGNALS. It has 5000 records in it.
I want to loop through this table. Do some calculations with the data
and add a record to a table named EQUITY.
I can't get the code to work after days of trying. Ready to give up.
Below is a shell just to prove the concept.
Public Sub test()
On Error GoTo errorrtn
Dim tradecount As Integer
'Declare record sets
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
Dim rst2 As ADODB.Recordset
Set rst2 = New ADODB.Recordset
'Set up the connection, name it cnn1 .
Dim cnn1 As ADODB.Connection
Set cnn1 = New ADODB.Connection
rst.LockType = adLockOptimistic
rst.Open "select * from signals", CurrentProject.Connection
Do Until rst.EOF
tradecount = tradecount + 1
' Add a new record to EQUITY table
With rst2
.ActiveConnection = CurrentProject.Connection
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open "select * from equity where id = 0 "
.AddNew
!id = tradecount
.Update
End With
rst.MoveNext
Loop
errorrtn:
Exit Sub
End Sub
I am new to ACCESS and need help with this.
I have a table named SIGNALS. It has 5000 records in it.
I want to loop through this table. Do some calculations with the data
and add a record to a table named EQUITY.
I can't get the code to work after days of trying. Ready to give up.
Below is a shell just to prove the concept.
Public Sub test()
On Error GoTo errorrtn
Dim tradecount As Integer
'Declare record sets
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
Dim rst2 As ADODB.Recordset
Set rst2 = New ADODB.Recordset
'Set up the connection, name it cnn1 .
Dim cnn1 As ADODB.Connection
Set cnn1 = New ADODB.Connection
rst.LockType = adLockOptimistic
rst.Open "select * from signals", CurrentProject.Connection
Do Until rst.EOF
tradecount = tradecount + 1
' Add a new record to EQUITY table
With rst2
.ActiveConnection = CurrentProject.Connection
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open "select * from equity where id = 0 "
.AddNew
!id = tradecount
.Update
End With
rst.MoveNext
Loop
errorrtn:
Exit Sub
End Sub