DoCmd.GoToRecord

J

Jeff

I am using the following code to navigate to the Previous Record, but I need
to add code to disable this Command Button if the current record happens to
be the First Record. Any suggestions?

Private Sub Command89_Click()

DoCmd.GoToRecord acActiveDataObject, , acPrevious, 1

End Sub
 
B

Beetle

In the Current event of your form put;

Private Sub Form_Current()

Me.Command89.Enabled = Me.CurrentRecord <> 1

End Sub
 
K

Klatuu

Here is a procedure I use that handles all 4 nav buttons, but you have to
use meaningful names. Command89 means nothing to anyone.

I call this from the form current event with:

Call SetNavButtons(Me)

Put the code in a standard module.

'---------------------------------------------------------------------------------------
' Procedure : SetNavButtons
' DateTime : 2/6/2006 09:36
' Author : Dave Hargis
' Purpose : Enables and Disables Nav buttons based on current record
position
'---------------------------------------------------------------------------------------
'
Sub SetNavButtons(ByRef frmSomeForm As Form)

On Error GoTo SetNavButtons_Error

With frmSomeForm
If .CurrentRecord = 1 Then
.cmdNextRec.Enabled = True
.cmdLastRec.Enabled = True
.cmdNextRec.SetFocus
.cmdFirstRec.Enabled = False
.cmdPreviousRec.Enabled = False
ElseIf .CurrentRecord = .Recordset.RecordCount 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