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
 
S

SteveS

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


Top