Show button ehen next record

G

Guest

Hi i have
On Error GoTo Err_Kommandoknap37_Click


DoCmd.GoToRecord , , acNext

Exit_Kommandoknap37_Click:
Exit Sub

Err_Kommandoknap37_Click:
MsgBox Err.Description
Resume Exit_Kommandoknap37_Click

But i only want to see the button if there are a next record
so if i'm on the lst record don't show the button
CAn i do that?

Regards
Alvin
 
G

Guest

Here is a Sub I use for exactly that purpose. It can be called from any
form. You have to be consistent about naming you nav buttons:

Sub SetNavButtons(SomeForm As Form)

On Error GoTo SetNavButtons_Error

With SomeForm
If .Recordset.AbsolutePosition = 0 Then
.cmdNextRec.Enabled = True
.cmdLastRec.Enabled = True
.cmdNextRec.SetFocus
.cmdFirstRec.Enabled = False
.cmdPreviousRec.Enabled = False
ElseIf .Recordset.AbsolutePosition = .Recordset.RecordCount - 1 Then
.cmdFirstRec.Enabled = True
.cmdPreviousRec.Enabled = True
.cmdPreviousRec.SetFocus
.cmdNextRec.Enabled = False
.cmdLastRec.Enabled = False
Else
.cmdFirstRec.Enabled = True
.cmdPreviousRec.Enabled = True
.cmdNextRec.Enabled = True
.cmdLastRec.Enabled = True
End If
End With

SetNavButtons_Exit:

On Error Resume Next
Exit Sub

SetNavButtons_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & _
") in procedure SetNavButtons of Module modFormOperations"
GoTo SetNavButtons_Exit

End Sub
 

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

Top