Stop a new record appearing

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

Guest

I have created a basic form for viewing existing data. For this purpose, I
have set the form not to allow additions. I have also used my own command
buttons for view first, last, previous and next records. However, when I
reach the last record, the 'next' button still display a 'new' record... How
can I stop this?
 
Rich,

Eliminate the navigation buttons by setting the form's Navigation buttons
property to No. Create your own forward and backward nav buttons if you
like.

Sprinks
 
Hi,

As I said, I created my own command buttons. I'm not using the built in
ones. It's the underlying 'next' function that automatically goes to a new
record after the last record. I need to keep the 'next' function but stop the
'new' record from being displayed.

I hope that's clearer.
 
Rich,

One way is to test if you're on a new record, and if so, move to the last.

If Me.NewRecord Then
DoCmd.GoToRecord , , acLast
End If
 
A way I have handled this is to use something like the following in the
form's Current event, where cmdPrev etc. are the names of your command
buttons:

Me.RecordsetClone.MoveLast

'Enable navigation buttons only when there are records available
Me.cmdPrev.Enabled = Not Me.CurrentRecord = 1
Me.cmdFirst.Enabled = Not Me.CurrentRecord = 1
Me.cmdNext.Enabled = (Me.CurrentRecord = 1 And Me.Recordset.RecordCount
Or Me.CurrentRecord < Me.Recordset.RecordCount
Me.cmdLast.Enabled = (Me.CurrentRecord = 1 And Me.Recordset.RecordCount
Or Me.CurrentRecord < Me.Recordset.RecordCount

With the Next button disabled at the last record you won't have the option
of going to a new record. The MoveLast line is so the Next and Last buttons
will be enabled if you open the form at the first record. If you are
opening the form to the last record the line of code is not needed.
 
Thanks guys,

I've gone for the option Bruce suggested in this particular case but I may
use the other option in future projects so thanks to you both.
 
Back
Top