GoToRecord, , acPrevious (1 Viewer)

GezB

New member
Local time
Today, 09:22
Joined
Jun 27, 2002
Messages
5
Can anyone help me work out how to avoid getting this error

I am using a command button/ sub procedure to move to the previous record in a form using the code

Docmd.GoToRecord, , acPrevious.

However if the form is already at the first/BOF record, clicking on my 'Previous Record' button creates an error "You cant go to the specified record."

What code do i need to prevent trying to go past the BOF record?

thanks

GezB:(
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 12:22
Joined
Feb 19, 2002
Messages
43,400
Code:
Private Sub cmdPrevious_Click()
On Error GoTo Err_cmdPrevious_Click

    DoCmd.GoToRecord , , acPrevious

Exit_cmdPrevious_Click:
    Exit Sub

Err_cmdPrevious_Click:
    Select Case Err.Number
        Case 2105
            MsgBox "You are already at the beginning", vbOKOnly
        Case Else
            MsgBox Err.Number & "-" & Err.Description
        End Select
    Resume Exit_cmdPrevious_Click
    
End Sub
 

GezB

New member
Local time
Today, 09:22
Joined
Jun 27, 2002
Messages
5
Awesome!

your fix works perfectly,

thanks a bunch

GezB:)
 

Users who are viewing this thread

Top Bottom