Finding the first record...

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to find the first record in the current form, and make sure that the PREVIOUS button is disabled when I am on that first record

(I get errors when I am on the first record and I click previous

The first field (primary key) in the table is called gameID, and it is an autonumber starting at 1. So I had it look for that record. Maybe my syntax is wrong for that function

Here is the code I have

Private Sub Form_Current(
'If the form is on a new record, we should disable the NEXT butto

'Shift the focus first, if there is a value in gameID, we must enabl
Dim firstrecord As Recordse

firstrecord = DoCmd.FindRecord(gameID = 1, , , , , , True

If Me.NewRecord = True The
cmdPrevious.SetFocu
cmdNext.Enabled = Fals
Els
cmdNext.Enabled = Tru
End I

If Me.CurrentRecord = firstrecord The
cmdPrevious.Enabled = Fals
End I

End Su
-----------------------------------------------

But the debugger keeps telling me

Expected function or variable at this line of code

firstrecord = DoCmd.FindRecord(gameID = 1, , , , , , True

Any ideas?
 
There's a better way to do this which involves using the recordsetclone.
Here's the basic idea - using the recordsetclone you attempt to navigate
back from the current record, if the BOF (Beginning of File) condition is
true, the current record is the first record so you disable the "Previous"
Button.

Using similar logic, you then attempt to move forward past the current
record. If the EOF condition is true, then the current record is the last
record so you would disable the "Next" button.

Since the recordsetclone can be navigated without distrubing the form, this
is all transparent to the user.

Instead of posting the sample code I will instead refer you to one of
Stephen Leban's samples - for Navigation buttons. This is all done in a
subform that you can drop onto any form. If you still want to code your own
buttons you can look at the code that he uses to enable/disable the
navigation buttons. There's a bit more to it than I've described above but
hopefully this will be enough to get you started.

http://www.lebans.com/recnavbuttons.htm
 
Back
Top