update previous record

G

Guest

I am looping through a query to create a master table from the fields in the
query. When the field "CRRT" changes, I need to go back to the last record
before it changed and put a number in the "BREAK" field. Thie following code
works but puts the break at the first record of the new "CRRT". The logic
doesn't make sense because I am telling it to move to the previous to edit
and then move to the next to resume the loop. Any clues? I have tried several
versions of the code below (moving the update command to different places,
etc.) and this is the only one I can get to work without error. It's just
putting the break in the wrong record.

With RS1
..MoveFirst
previous = RS1.Fields("CRRT")
current = RS1.Fields("CRRT")
Do Until .EOF
RS2.AddNew
RS2.Fields("OEL") = .Fields("WALKSEQ") + "********************* ECRWSS **" +
..Fields("CRRT")
RS2.Fields("ZIP4DPC") = .Fields("ZIP") + .Fields("DPC")
RS2.Fields("FULLNAME") = .Fields("NAME")
RS2.Fields("ADDR") = .Fields("ADDR")
RS2.Fields("CSZ") = .Fields("CITY") + " " + .Fields("ST") + " " +
..Fields("ZIP")
RS2.update
If current <> previous Then
RS2.MovePrevious
RS2.Edit
RS2.Fields("BREAK") = break
RS2.update
RS2.MoveNext
break = break + 1
Else
RS2.MovePrevious
RS2.Edit
RS2.Fields("BREAK") = Null
RS2.update
RS2.MoveNext
End If


previous = .Fields("CRRT")
..MoveNext
current = .Fields("CRRT")
Loop
End With
 
G

Guest

Hard to tell just reading through it, but the location of "BREAK = BREAK +
1" looks suspicious. Try putting a breakpoint in the top of your code and
stepping through it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top