Next button code question... (1 Viewer)

uniboy

Registered User.
Local time
Today, 07:04
Joined
Feb 11, 2011
Messages
16
Iv got Next and Previous buttons, both of which work. When I get to the start of the record set my error message appears which is great. but when i get to the end of the record set, my error message does not appear. Here is my code, im sure its just a little thing i need to change but I just cant find it:

'This goes to the next record
Private Sub cmdNext_Click()
On Error GoTo Err_bNext_Click

If Me.Dirty Then
MsgBox "Please save the changes to the record." & vbCrLf & vbLf & "You can not advance from this record until you Save the changes made, or Delete the record.", vbExclamation, "Save Required"
ElseIf Me.CurrentRecord < Me.RecordsetClone.RecordCount Then
DoCmd.GoToRecord , , acNext
End If

Exit_bNext_Click:
Exit Sub

Err_bNext_Click:
MsgBox "Please click Previous to view previous records.", vbExclamation, "End of Record Set"
Resume Exit_bNext_Click
End Sub


'This goes to the previous code
Private Sub cmdPrevious_Click()

On Error GoTo Err_bPrevious_Click

If Me.Dirty Then
MsgBox "Please save the changes to the record." & vbCrLf & vbLf & "You can not advance from this record until you Save the changes made, Delete the record or Undo the changes made.", vbExclamation, "Save Required"
ElseIf Me.CurrentRecord <= Me.RecordsetClone.RecordCount Then
DoCmd.GoToRecord , , acPrevious
End If

Exit_bPrevious_Click:
Exit Sub

Err_bPrevious_Click:
MsgBox "Please click Next to view more records.", vbExclamation, "Start of Record Set"
Resume Exit_bPrevious_Click

End Sub
 

RuralGuy

AWF VIP
Local time
Today, 01:04
Joined
Jul 2, 2005
Messages
13,826
The Recordset.RecordCount is *not* guaranteed accurate until after you have gone to the last record in the Recordset. (Movelast)
 

vbaInet

AWF VIP
Local time
Today, 07:04
Joined
Jan 22, 2010
Messages
26,374
Are you talking about the error message in the error handler or your verification msgbox?
 

uniboy

Registered User.
Local time
Today, 07:04
Joined
Feb 11, 2011
Messages
16
im talking about my error message, which is:

MsgBox "Please click Previous to view previous records.", vbExclamation, "End of Record Set"

I want that message to appear when I try and click Next on the last record.

any ideas mate?
 

DCrake

Remembered
Local time
Today, 07:04
Joined
Jun 8, 2005
Messages
8,632
There are only 4 possible outcomes

1. EOF = True + BOF = True - No records
2. EOF = True + BOF = False - Last Record
3 .EOF = False +BOF = True - First Record
4. EOF = False + BOF = False - Somewhere inbetween

1 Cannot go backward or forward
2 Backwards only
3 Forwards only
4 forwards and backwards

Each time you click on any of the button you need to test for the matching condition and respond accordingly.
 

vbaInet

AWF VIP
Local time
Today, 07:04
Joined
Jan 22, 2010
Messages
26,374
You will find that the BOF and EOF properties don't work on a form's recordset.

I don't see why that message will not appear if there are unsaved changes. I suspect that somewhere in your code you are forcing the record to be saved.
 

Users who are viewing this thread

Top Bottom