Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MoveNext not working

Status
Not open for further replies.

dmccallum

Programmer
Jan 5, 2001
90
US
I have a loop using the database JobCost to look at the field del_date and I've inserted a MsgBox that shows me the data in del_date. I loop through the database but the del_date never changes from the first record. What am I doing wrong?

Do While rsJobCost.EOF = False
rsJobCost.MoveNext
MsgBox Left(del_date, 4)
If Left(del_date, 4) <> YearTxt Then
YTD = YTD
End If

If Left(del_date, 4) = YearTxt Then
YTD = YTD + Tot_Sales
End If


Loop

 
Maybe this isn't the problem, but your recordset object should be along with the field name separated by an exclamation mark.
Code:
MsgBox Left(rsJobCost!del_date, 4) 'etc.

Also, placing the MoveNext statement at the top of the loop will skip your first record. It should be placed at the end of the loop. (That may be what you intended, though.)
 
hi,

Your problem is the movenext statement. This statement should be on the bottom of your code, just before the loop.
You code should be like this

Do While rsJobCost.EOF = False
rsJobCost.MoveFirst
MsgBox Left(del_date, 4)
If Left(del_date, 4) <> YearTxt Then
YTD = YTD
End If

If Left(del_date, 4) = YearTxt Then
YTD = YTD + Tot_Sales
End If
rsJobCost.MoveNext

Loop

Good luck
 
Actually, your 'MoveFirst' statement needs to be outside the loop, otherwise you keep returning to the first record with every cycle. Try it like this:

rsJobCost.MoveFirst
Do While rsJobCost.EOF = False

MsgBox Left(del_date, 4)
If Left(del_date, 4) <> YearTxt Then
YTD = YTD
End If

If Left(del_date, 4) = YearTxt Then
YTD = YTD + Tot_Sales
End If
rsJobCost.MoveNext

Loop

Hope this does it for you.
 
yes you are right andyclt.
I was in a hurry so I didn't pay attention.
Thanks for pointing this out.

Grt Imhoteb
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top