Trancemission
Technical User
I am an avid Unix DB programmer but have a current project tidying up Access. I have done some VBA coding before but seem to be having a little problem which I cannot solve. This simple code bombs out with:
'Run-time error '3705'
Operation is not allowed when the object is open'
However if i move rstRate.Open about the For x line:
Seems to work fine, even if I have For x = 1 to 50 :?
Trancemission
=============
If it's logical, it'll work!
'Run-time error '3705'
Operation is not allowed when the object is open'
Code:
'Declare vars
Dim cur As String
Dim x As Integer
'Db
Dim rst As Recordset
Dim cnn As Connection
Set cnn = New ADODB.Connection
Set cnn = CurrentProject.Connection
Set rst = New ADODB.Recordset
'
Dim rstEx As Recordset
Dim cnnEx As Connection
Set cnnEx = New ADODB.Connection
Set cnnEx = CurrentProject.Connection
Set rstRate = New ADODB.Recordset
'Run query, add to rst recordset
rst.Open "[b]SQL TO GET CURERNCY[/b];", cnnEx, adOpenKeyset, adLockReadOnly, adCmdText
cur = rst!Currency
'Loop through records
x = 0
For x = 1 To rst.RecordCount
'Get Currency
rstRate.Open "SELECT exchange_rates.currency, exchange_rates.rate, exchange_rates.code FROM exchange_rates WHERE exchange_rates.code like '" & cur & "';", cnn, adOpenKeyset, adLockReadOnly, adCmdText
However if i move rstRate.Open about the For x line:
Code:
rstRate.Open "SELECT exchange_rates.currency, exchange_rates.rate, exchange_rates.code FROM exchange_rates WHERE exchange_rates.code like '" & cur & "';", cnn, adOpenKeyset, adLockReadOnly, adCmdText
'Loop through records
x = 0
For x = 1 To rst.RecordCount
'Get Currency
Seems to work fine, even if I have For x = 1 to 50 :?
Trancemission
=============
If it's logical, it'll work!