Hope someone out there can help. I'm a newbie with limited VB5 experience. I'm working through what I thought would be a simple loop structure to read multiple records in an MS Access table, calculate a value from each record, cumulate these values and report the total. The problem I am having is that the loop never leaves the initial record. It iterates through each record properly but the calculations it performs is always against the 1st record in the file.<br>
<br>
I'm attaching the code (it's short!!) in hopes someone can pick out my obvious error.<br>
<br>
Any help would be appreciated.<br>
<br>
Private Sub ROI_Click()<br>
Dim dbMydb As Database<br>
Dim recinvest As Recordset<br>
Set dbMydb = OpenDatabase _<br>
("C:\My Documents\Invest2.mdb"
<br>
Set recinvest = dbMydb.OpenRecordset("Invests"
<br>
<br>
Dim Days As Double<br>
Dim days1 As Double<br>
Dim Gain As Single<br>
Dim gaintot As Single<br>
Dim Years As Single<br>
purch_date = recinvest("purch_date"
<br>
market = recinvest("market"
<br>
cost = recinvest("cost"
<br>
Days = 0<br>
days1 = 0<br>
gaintot = 0<br>
With recinvest<br>
Do Until .EOF<br>
Days = Now - purch_date<br>
Gain = market - cost<br>
days1 = days1 + Days<br>
gaintot = gaintot + Gain<br>
Years = Days / 365<br>
Print gaintot<br>
.MoveNext<br>
Loop<br>
.Close<br>
End With<br>
End Sub<br>
<br>
I'm attaching the code (it's short!!) in hopes someone can pick out my obvious error.<br>
<br>
Any help would be appreciated.<br>
<br>
Private Sub ROI_Click()<br>
Dim dbMydb As Database<br>
Dim recinvest As Recordset<br>
Set dbMydb = OpenDatabase _<br>
("C:\My Documents\Invest2.mdb"
Set recinvest = dbMydb.OpenRecordset("Invests"
<br>
Dim Days As Double<br>
Dim days1 As Double<br>
Dim Gain As Single<br>
Dim gaintot As Single<br>
Dim Years As Single<br>
purch_date = recinvest("purch_date"
market = recinvest("market"
cost = recinvest("cost"
Days = 0<br>
days1 = 0<br>
gaintot = 0<br>
With recinvest<br>
Do Until .EOF<br>
Days = Now - purch_date<br>
Gain = market - cost<br>
days1 = days1 + Days<br>
gaintot = gaintot + Gain<br>
Years = Days / 365<br>
Print gaintot<br>
.MoveNext<br>
Loop<br>
.Close<br>
End With<br>
End Sub<br>