Detect if 1st Record

S

Scott

Below I have code for 2 buttons, one sub for next record button and one sub
for a previous button. In sub cmdNext_Click() I have code that detects if
the record is new and if it is and user clicks next again, don't display
access's warning.

However, I'm trying to figure out how to do the same for a previous button.
If user is on 1st record in the form and clicks previous button, I'd like to
suppress access's warning message.

Is this possible?

CODE ****************

Private Sub cmdNext_Click()
On Error GoTo Err_cmdNext_Click

If (Not Screen.ActiveForm.NewRecord) Then
DoCmd.GoToRecord , , acNext
Me!userLast.SetFocus
End If

Exit_cmdNext_Click:
Exit Sub

Err_cmdNext_Click:
MsgBox Err.Description
Resume Exit_cmdNext_Click

End Sub

Private Sub cmdPrevious_Click()
DoCmd.GoToRecord , , acPrevious
End Sub
 
G

Guest

There are many ways to do this....her is a quick and dirty wat:

Private Sub cmdPrevious_Click()
On Error GoTo OhNo
DoCmd.GoToRecord , , acPrevious

WeBGone:
Exit Sub

OhNo:
'ignore error # 2105 - 'You can't go to the specified record'
If Err.Number <> 2105 Then
MsgBox Err.Number & " - " & Err.Description
End If
Resume WeBGone

End Sub


HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Next button - error when arrived at end of records 5
Next record button 3
Navigation buttons 2
Navigation Buttons 7
next buton NOT NEW 6
Next button problem 2
DoCmd.GoToRecord 2
Combining code isn't working 5

Top