Advertisement

04.09.2008 at 02:21AM PDT, ID: 23307520
[x]
Attachment Details

Access Loop problem

Asked by martywal in Microsoft Access Database, Visual Basic Programming

Tags: , , , ,

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_rates")

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
[+][-]04.09.2008 at 02:28AM PDT, ID: 21313062

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Access Database, Visual Basic Programming
Tags: Microsoft, Access, 2003, VBA - Loop problem, VBA
Sign Up Now!
Solution Provided By: peter57r
Participating Experts: 1
Solution Grade: A
 
 
[+][-]04.09.2008 at 03:20AM PDT, ID: 21313312

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.09.2008 at 03:32AM PDT, ID: 21313362

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628