PDA

View Full Version : Previous record command button



FrymanTCU
04-17-2008, 12:42 PM
Private Sub cmdPriorRecord_Click()
On Error GoTo Err_cmdPriorRecord_Click
DoCmd.GoToRecord , , acPrevious
Exit_cmdPriorRecord_Click:
Exit Sub
Err_cmdPriorRecord_Click:
MsgBox Err.Description
Resume Exit_cmdPriorRecord_Click

End Sub

Why does this error when it is at the first record in my form?

Trevor
04-17-2008, 04:46 PM
Access is weird somtimes, so here's one of mine with out the command button, with warning msg:

DoCmd.GoToRecord , , acPrevious
Exit_Previous_Record_Button_Click:
Exit Sub
Err_Previous_Record_Button_Click:
MsgBox "You cannot go backward any further", _
vbOKOnly + vbInformation, "Can't go backward ..."
Resume Exit_(your command button here)_Click
Endd:
End Sub

ben.oates
04-18-2008, 03:42 AM
It errors on the first item because there is no previous item. You should check that you're not at BOF before calling the DoCmd and then shift to EOF if you are and want it to loop round or ignore the request (or msgbox) otherwise.

FrymanTCU
04-18-2008, 09:46 AM
It errors on the first item because there is no previous item. You should check that you're not at BOF before calling the DoCmd and then shift to EOF if you are and want it to loop round or ignore the request (or msgbox) otherwise.

I like that idea and I tried to build it into an IF statement but I keep getting the message: Variable not Defined? Is the BOF not applicable to a form?:dunno

CreganTur
04-18-2008, 11:57 AM
No, you can use EOF and BOF in forms- the issue is that you're telling Acces to look for a BOF or EOF, but not telling it what recordset to use- it's undefined.

Try something like:Dim rs As Recordset
Set rs = Me.Recordset.Clone'<<<make clone of form's recordset

'Check to see if at beginning of recordset
If rs.BOF Then
'Some Action
ElseIf rs.EOF Then
'Some Action
End If