N
nerb61 via AccessMonster.com
How can I hide the Next and Previous buttons when there are no Next and
Previous records?
Previous records?
That line of code does not go with the rest.
I guess my instructions were incomplete. Put that line of code in all four
buttons. First, Previous, Next, and Last.
Put the rest of the code in a standard module. That way, you can use it on
any form. that is why you pass it the form.
Then, reread my earlier post on how the buttons should be named.
Now, here is the code for all the buttons:
Private Sub cmdFirstRec_Click()
On Error GoTo cmdFirstRec_Click_Error
On Error GoTo Err_cmdFirstRec_Click
If Me.NewRecord Then
Me.Dirty = False
Else
DoCmd.GoToRecord , , acFirst
Call SetNavButtons(Me)
End If
Exit_cmdFirstRec_Click:
Exit Sub
Err_cmdFirstRec_Click:
MsgBox Err.Description
Resume Exit_cmdFirstRec_Click
cmdFirstRec_Click_Exit:
On Error Resume Next
Exit Sub
cmdFirstRec_Click_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & _
") in procedure cmdFirstRec_Click of VBA Document
Form_frmAttributetable"
GoTo cmdFirstRec_Click_Exit
End Sub
Private Sub cmdPreviousRec_Click()
On Error GoTo cmdPreviousRec_Click_Error
On Error GoTo Err_cmdPreviousRec_Click
If Me.NewRecord Then
Me.Dirty = False
Else
DoCmd.GoToRecord , , acPrevious
Call SetNavButtons(Me)
End If
Exit_cmdPreviousRec_Click:
Exit Sub
Err_cmdPreviousRec_Click:
MsgBox Err.Description
Resume Exit_cmdPreviousRec_Click
cmdPreviousRec_Click_Exit:
On Error Resume Next
Exit Sub
cmdPreviousRec_Click_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & _
") in procedure cmdPreviousRec_Click of VBA Document
Form_frmAttributetable"
GoTo cmdPreviousRec_Click_Exit
End Sub
Private Sub cmdNextRec_Click()
On Error GoTo cmdNextRec_Click_Error
If Me.NewRecord Then
Me.Dirty = False
Else
DoCmd.GoToRecord , , acNext
Call SetNavButtons(Me)
End If
cmdNextRec_Click_Exit:
On Error Resume Next
Exit Sub
cmdNextRec_Click_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & _
") in procedure cmdNextRec_Click of VBA Document
Form_frmAttributetable"
GoTo cmdNextRec_Click_Exit
End Sub
Private Sub cmdLastRec_Click()
On Error GoTo cmdLastRec_Click_Error
On Error GoTo Err_cmdLastRec_Click
If Me.NewRecord Then
Me.Dirty = False
Else
DoCmd.GoToRecord , , acLast
Call SetNavButtons(Me)
End If
Exit_cmdLastRec_Click:
Exit Sub
Err_cmdLastRec_Click:
MsgBox Err.Description
Resume Exit_cmdLastRec_Click
cmdLastRec_Click_Exit:
On Error Resume Next
Exit Sub
cmdLastRec_Click_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & _
") in procedure cmdLastRec_Click of VBA Document
Form_frmAttributetable"
GoTo cmdLastRec_Click_Exit
End Sub
[quoted text clipped - 52 lines]I tried the code and get a Compile error: Expected End Sub after the
SetNaveButtons (Me)