First / Last nav button disable

P

Paul B.

I am having trouble with my code. When I open the form, and there is only one
record, only my Next and Last Nav Buttons are disabled, when all of them
should be.

Any help would be appreciated.

-------------
Private Sub Form_Load()

Dim rst As DAO.Recordset
Dim lngCount As Long

Set rst = Me.RecordsetClone

With rst
.MoveFirst
.MoveLast
lngCount = .RecordCount
End With

If Me.CurrentRecord = lngCount Then
Me.cmdLastRecord.Enabled = False
Me.cmdNextRecord.Enabled = False
Me.cmdPreviousRecord.Enabled = True
Me.cmdFirstRecord.Enabled = True
ElseIf Me.CurrentRecord = 1 Then
Me.cmdLastRecord.Enabled = True
Me.cmdNextRecord.Enabled = True
Me.cmdPreviousRecord.Enabled = False
Me.cmdFirstRecord.Enabled = False
Else
Me.cmdLastRecord.Enabled = True
Me.cmdNextRecord.Enabled = True
Me.cmdPreviousRecord.Enabled = True
Me.cmdFirstRecord.Enabled = True

End If

End Sub

---------------
 
M

Maurice

When the form is loaded and there is one record your lngCount is set to one
so it will never get to your elseif statement....

Try this:

Private Sub Form_Load()

Dim rst As DAO.Recordset
Dim lngCount As Long

lngCount = Me.RecordsetClone.recordcount


If Me.CurrentRecord = lngCount Then
Me.cmdLastRecord.Enabled = False
Me.cmdNextRecord.Enabled = False
Me.cmdPreviousRecord.Enabled = True
Me.cmdFirstRecord.Enabled = True
ElseIf Me.CurrentRecord = 1 Then
Me.cmdLastRecord.Enabled = True
Me.cmdNextRecord.Enabled = True
Me.cmdPreviousRecord.Enabled = False
Me.cmdFirstRecord.Enabled = False
Else
Me.cmdLastRecord.Enabled = True
Me.cmdNextRecord.Enabled = True
Me.cmdPreviousRecord.Enabled = True
Me.cmdFirstRecord.Enabled = True

End If

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

Top