Blocking a 'next record' action on a form

jonwebb

New Member
Joined
Nov 8, 2004
Messages
17
Hi,

Hope someone can help. I'm building a form to allow users to enter data and want them to be able to scroll through records adding and reviewing data. When they want to add new data, they go to the last/new record button and add it there. However, if they are reviewing and go to the new record, they can't actually go back because it would violate the primary key (certain fields are auto populated, making up a partial key on the table).

Is there any way of using the navigation buttons to only go from the first to last existing records, whilst having it in edit mode? I then want to give them a button to add a new record which I've figured out how to do. If they add a new record by mistake that's their own problem!

Thanks in advance,
Jon
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
You can set the form properties (manually and through code) for 'AllowAdditions' to false, this will prevent adding new records.

Your button to add a new record (I imagine you're using docmd.gotorecord,,acNewRecord) should also set 'AllowAdditions' to true.

To help avoid the annoying key messages, you can use the form_before update event to test for the current record to be 'dirty', which means they are in the middle of entering data, but haven't left the record yet.
Code:
If me.dirty then .....
You can them prompt them to enter specific information. You could also ask them if they want to exit the record without saving, if so, using:
Me.Undo (which is the same as hitting ESC)
will back them out of the current 'dirty' record.
 
Upvote 0

Forum statistics

Threads
1,221,831
Messages
6,162,252
Members
451,757
Latest member
iours

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top