navigation buttons

G

Guest

I want to activate/deactivate navigation buttons on my form depending on the
current record. At present I am using the code:

If Me.CurrentRecord = 1 Then
Me.GotoPreviousbutton.Enabled = False
Me.GotoFirstbutton.Enabled = False
Else
Me.GotoPreviousbutton.Enabled = True
Me.GotoFirstbutton.Enabled = True
End If

which works ok for GotoPrevious and GotoFirst buttons. I want to do the same
for GotoNext and GotoLast. On this newsgroup I have found the code:

If Me.BOF Then
Me.GotoPreviousbutton.Enabled = False
Me.GotoFirstbutton.Enabled = False
Else
Me.GotoPreviousbutton.Enabled = True
Me.GotoFirstbutton.Enabled = True
End If

If Me.EOF Then
Me.GotoLastbutton.Enabled = False
Me.GotoNextbutton.Enabled = False
Else
Me.GotoLastbutton.Enabled = True
Me.GotoNextbutton.Enabled = True
End If

which is giving me compilation orrors in Me.BOF and Me.EOF lines. What I
have to change / add to make it working ?

Thanks for help.

Tony
 
S

Steve Schapel

Tony,

Try it like this...

Me.GotoPreviousbutton.Enabled = Me.CurrentRecord > 1
Me.GotoFirstbutton.Enabled = Me.CurrentRecord > 1
Me.GotoLastbutton.Enabled = Me.CurrentRecord <
Me.RecordsetClone.RecordCount
Me.GotoNextbutton.Enabled = Me.CurrentRecord <
Me.RecordsetClone.RecordCount
 
G

Guest

I have modified the code to:

Private Sub Form_Current()

Dim rst As DAO.Recordset
Dim lngCount As Long

Set rst = Me.RecordsetClone

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

If lngCount = 1 Then
Me.GotoPreviousbutton.Enabled = False
Me.GotoFirstbutton.Enabled = False
Me.GotoLastbutton.Enabled = False
Else
If Me.CurrentRecord = lngCount Then
Me.GotoLastbutton.Enabled = False
Me.GotoPreviousbutton.Enabled = True
Me.GotoFirstbutton.Enabled = True
ElseIf Me.CurrentRecord = 1 Then
Me.GotoLastbutton.Enabled = True
Me.GotoFirstbutton.Enabled = False
Me.GotoPreviousbutton.Enabled = False
Else
Me.GotoPreviousbutton.Enabled = True
Me.GotoFirstbutton.Enabled = True
Me.GotoLastbutton.Enabled = True
End If
End If

End Sub

It is working when there are some records with data, but is giving me errors
when there is no data. How I should modify the lines

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

to fix the problem.

Thanks for help.

Tony
 
V

Van T. Dinh

With rst
If Not .EOF Then
.MoveLast
lngCount = .RecordCount
Else
' Empty RecordSource
lngCount = 0
End If
End With
 

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