DoCmd.GoToRecord - First record

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

Guest

hi!

i've got a form & created command buttons for the Previous & Next Record
-using
DoCmd.GoToRecord , , acPrevious ... to go to the previous record. All
works fine until i get to the first record. if i press the Previous button
again an error pops up coz i cannot go past the first record.

i can i check if i have reached the first record? also for the last record.

thanks

Dave
 
There are a couple of options here. First, you could trap the error and
ignore it. The other option is to do what you've asked, detect that you're
at the first or last record.

To see if you're at the first record,

If Me.Recordset.AbsolutePosition = 0 Then

To see if you're at the last record,

If Me.Recordset.AbsolutePosition = Me.Recordset.RecordCount -1 Then

If you're at a new record, the result of checking for the last record will
be the same as if you're at the last record. To test for a new record use,

If Me.NewRecord Then

For a form connected to a table with no records,
Me.RecordSet.AbsolutePosition returns -1.
 
hi!

i've got a form & created command buttons for the Previous & Next Record
-using
DoCmd.GoToRecord , , acPrevious ... to go to the previous record. All
works fine until i get to the first record. if i press the Previous button
again an error pops up coz i cannot go past the first record.

i can i check if i have reached the first record? also for the last record.

thanks

Dave

Code the Form's Current event:

CmdPreviousRecord.Enabled = Not Me.CurrentRecord = 1
CmdNextRecord.Enabled = Me.CurrentRecord = 1 Or Me.CurrentRecord <
Me.Recordset.RecordCount


Change the command button names to whatever you call your command
buttons.
 
Back
Top