DoCmd.GoToRecord - First record

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
 
W

Wayne Morgan

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.
 
F

fredg

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.
 

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