Hi Experts,
I am having a problem with a loop statement that helps me build a table that shows the daily currency rates for currencies from the last day it was run. The problem I am having is with the GBP (which will alwasy = 1, 1, 1 for rs!1, rs!2 & rs!3 respectively. At the moment it just keeps adding the day over and over and over again. I'm pretty sure it is a simple problem but can't seem to get it. Any help much appreciated, here's the code:
Function Add_rates()
Dim db As Database, rs As Recordset, Cur As String, dat As Date, v1 As Double, v2 As Double, v3 As Double
Set db = CurrentDb
Set rs = db.OpenRecordset("Qry_Add_
missing_ra
tes")
On Error GoTo fellover
rs.MoveFirst
first:
Cur = rs!currency
dat = rs!Date_of_rate
v1 = rs!r1
v2 = rs!r2
v3 = rs!r3
rs.MoveNext
other:
Do Until rs.EOF
If Cur = rs!currency Then
If dat = (rs!Date_of_rate - 1) Then
Cur = rs!currency
dat = rs!Date_of_rate
v1 = rs!r1
v2 = rs!r2
v3 = rs!r3
rs.MoveNext
Else
'insert missed rates
rs.AddNew
rs!currency = Cur
dat = dat + 1
rs!Date_of_rate = dat
rs!r1 = v1
rs!r2 = v2
rs!r3 = v3
rs.Update
rs.Requery
GoTo first
End If
Else
If dat = Forms!TOADhome!Text4 Or dat > Forms!TOADhome!Text4 Then
GoTo first
Else
rs.AddNew
rs!currency = Cur
dat = dat + 1
rs!Date_of_rate = dat
rs!r1 = v1
rs!r2 = v2
rs!r3 = v3
rs.Update
rs.Requery
GoTo first
End If
End If
Loop
'If dat = Forms!TOADhome!Text4 Then
' GoTo GBP_Finish
' Else
' GoTo GBP_other
' End If
GBP_first:
dat = Forms!TOADhome!MaxRatetxt
rs.AddNew
rs!currency = "GBP"
rs!Date_of_rate = dat
rs!r1 = 1
rs!r2 = 1
rs!r3 = 1
rs.Update
GBP_other:
dat = dat + 1
rs.AddNew
rs!currency = "GBP"
rs!Date_of_rate = dat
rs!r1 = 1
rs!r2 = 1
rs!r3 = 1
rs.Update
If dat = Forms!TOADhome!TomorrowTXT
Then
GoTo GBP_Finish
Else
GoTo GBP_other
End If
GBP_Finish:
Exit Function
fellover:
MsgBox Err.Description
End Function
Start Free Trial