Looping in a form

My understanding of your description:

You have a form with 2 buttons

Previous Next

If you continue to press/click Previous (from wherever you are positioned) it will take you to the previous record, and if you happen to be on the first record and click Previous, you will be taken to the LastRecord in the recordset.
Similarly if you click Next, you go to the next record based on absolute position, And if you happen to be at the LastRecord in the recordset, you will be taken to the First(absolute position) in the recordset.

Based on earlier posts, I thought this was working.
Please me what isn't working or what exactly you need/want.
 
Ok, now I feel really, really stupid...I didn't test it :o and the going from the first to the last record works, but going from the last the the first gives the error "No Current Record."

Also, I have the form (That from a list box opens up the the item that is double clicked) but, the 2nd form it opens upon double click, is a filtered to that item, I would like to be able to click next, and it removes the filter, and stays on the item, then goes next. My current set up has it so there is a button that removes the filter, but it sets my the the first item in the records.
 
I was just looking at your code
Code:
Private Sub cmdPrev_Click()
On Error GoTo Err_mdPrev_Click

With Me.Recordset
  If .AbsolutePosition < .RecordCount Then
    .MovePrevious
  Else
    .MoveLast
  End If
End With

Exit_cmdPrev_Click:
    Exit Sub

Err_cmdPrev_Click:
    MsgBox Err.Description
    Resume Exit_cmdPrev_Click
    
End Sub
I think, but untested:

If you are working with Previous, you want to check that your current position is >0, and if so then MovePrevious. And, if your current position is 0 (ie. not >0), then you want to MoveLast

so this line
Code:
 If .AbsolutePosition < .RecordCount Then
may need to be

Code:
 If .AbsolutePosition > 0 Then

Thoughts?
Also, I haven't looked at the second part of your question--- 1 step at a time.
 
Ok, odd, my prevouise code is


Code:
Private Sub cmdPrev_Click()
On Error GoTo Err_cmdPrev_Click

With Me.Recordset
 If .AbsolutePosition < .RecordCount Then
.MoveLast
Else
.MovePrevious
End If

End With

Exit_cmdPrev_Click:
    Exit Sub

Err_cmdPrev_Click:
    MsgBox Err.Description
    Resume Exit_cmdPrev_Click

But it just jumps me to the last record in the database.
 
Code:
With Me.Recordset
 If .AbsolutePosition < .RecordCount Then
.MoveLast...

This is saying,
if the absolute position I am at is less than the end of the file,
then move to the last record. It is not checking that you are at the first record--just any record that isn't the last record.
 
Last edited:
So...I Would want to tell it that if I am at the first record, then move to the last?
 
Last edited by a moderator:
If you are on the first record, and you want to move Previous--there is NO previous. This would typically be an error condition. The code related to the previous button intercepts/accounts for the condition and says --if I'm on the first record, and ask to movePrevious, I want you to position at the Last record in the record set.

You are the one who identified the logic to be programmed - is this not what you want??
 
It is, I am just getting very confused with my self, sorry about that.
 
Are you still confused?

Conceptually it is much like a position on a CD/DVD.
If you are at the very start, and ask to move Previous--there is no Previous. So your logic said then move me to the very Last/End so I can continue to use the MovePrevious.

Perhaps it is better to say --move from my current absolute position to a position 1 less than where I am...
and if I am at the very beginning, then move me to the very Last/End
 
That makes a lot more sense when explained that way.
 

Users who are viewing this thread

Back
Top Bottom