Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cancelling Insert Record 1

Status
Not open for further replies.

jjob

Programmer
Joined
Jul 16, 2002
Messages
157
Location
GB
I am amending an existing app and have a problem where it is possible for the user to get into the "New Record" screen, then decide not to continue and navigate back, however referential integrity rules kick in and the user gets a message saying a value is required and the user can't navigate back until a valid record is entered. The new record is generated by

DoCmd.GoToRecord , , acNewRec

there is no money available for extensive re-working so that the Insert would be controlled via code/SQL etc, so does anyone have an answer as to how to cancel out of the new record via an event or simple code?

TIA

John

 
You have the following options (and probably more):

(a) No changes required to the application. If the user hits the escape key twice whilst entering the new record, any new record field entries will be cancelled, and the user will be able to move off the record without Ref Integerity problems (because the new record will not be created).

(b) Use the controls wizard on the toolbar to create a special button to undo any fields added to the current record (ie. create a command button, select the Record Operations category, then select the Undo Record action). The user will then have to click this button to cancel the new record entries before attempting to move off it.

(c) Create your own 'undo' button with the following code:
DoCmd.RunCommand acCmdUndo

(d) Add code to the before update event which includes some form of validation of the current record's data, with appropriate error handling and cancellation of the update attempt if the data is found to be inconsistent. This is the cleanest and most professional way of handling the situation.

Cheers,

Steve Lewy
Solutions Developer
steve@lewycomputing.com.au
 
TVM Steve,

Your answer helped me solve it, but the problem turned out to be a bit odd. I was testing code changes as you suggested when I discovered the message only occured when I tried a DlookUp using an id of Zero (caused by an empty field) - this value was not a key field in the Dlookup source table, and the message appeared! Stopping the Dlookup if the field was Zero as well as the existing Null check solved the problem.

Thanks again.

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top