Move to a specific row

mfaqueiroz

Registered User.
Local time
Today, 02:49
Joined
Sep 30, 2015
Messages
125
Hei :)

I'm doing a code that compares two tables(AF1,AF2) with 2 for cycles. I want that when first for cycle ends the next for cycle begins at AF2 stopped.

So, I recorded the ID2 and I've write( as are in red) AF1.Move ID2
but isn't working, it moves for a row very far away of what i pretend...any sugestion?:)




End = DCount("[ID]", "H1")

AF1.MoveFirst
For x = 1 To End
Day1 = DateValue(AF1.Fields(2).Value)
ID1 = AF1.Fields(0).Value

AF2.MoveFirst
For y = 1 To End
ID2 = AF2.Fields(0).Value

If Day1=Day2 Then
AF2.Edit
AF2.Fields(13).Value = "I"
AF2.Update

Flag = 1

If Flag = 1 Then
y = FimA
End If

End If
End If

AF2.MoveNext
Next y

AF1.MoveFirst
AF1.Move ID2


Next x

End Sub
 
Firstly, you'd make it easier on yourself and anyone else reading your code if you used field names and instead of relative fields
ie use AF1!Mydate instead of AF1.Fields(2)

What is stored in Day2? I see nothing changing it in your code.
 
Thank You :) I'll explain better
There are two tables with a date field, I'm comparing this value, when the dates are different I add a flag to indicate that the day changed. [AF2!Flag = "I""]

So, when I go back for the for cycle i want that it begins where the last for cycle ended. In the same position.

In a generic way, my doubt is how can I move to a specific row of my query using the vba?
I used the rs.Next xxx, but it goes to a record away from xxx.

Thanks,
I hope that it was more clear :)

End = DCount("[ID]", "H1")

AF1.MoveFirst
For x = 1 To End
Day1 = AF1!Mydate
ID1 = AF1!MyID

AF2.MoveFirst
For y = 1 To End
ID2 = AF2!MyID
Day2 = AF2!Mydate

If Day1=Day2 Then
AF2.Edit
AF2!Flag = "I"
AF2.Update

Flag = 1

If Flag = 1 Then
y = End
End If

End If
End If

AF2.MoveNext
Next y

AF1.MoveFirst
AF1.Move ID2


Next x

End Sub
 

Users who are viewing this thread

Back
Top Bottom