Navigation tab, undorecord on exit event

Kamolga

Well-known Member
Joined
Jan 28, 2015
Messages
1,185
Hi,

I have a form to add new employees (LastName and FirstName with new unseen EmployeeID) to Employees table. I have a save (it saves the record and goto NewRecord) and cancel button
Code:
RunMenuCommand
             Command UndoRecord
, which basically delete what is typed in both fields of the form.

Both work as expected.

My problem is since I put this form in a navigation form, if I type something and leave the tab, it will save the record and I would like to avoid that.

I thought "Easy, I will apply the RunMenuCommand UndoRecord as above but on exit event"
Unfortunately I recieve an error message that maybe database is in read only or maybe the undoRecord is not supported by this version of Access (which make no sense since the cancel button works).
Strangely enough, the message comes when I come on the tab, not when I leave it.

Should I add a condition to the exit event that if there are caracters in one of the fiels, undo record or is it the RunMenuCommand that can not be associated to a tab? Any suggestion?
 
Last edited:

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
I've never used a nav form that I didn't build myself and after reading about their issues, probably never will. Thus I can only make observations based on that, and since you've had 90 views with no replies, I'll share what little I know about them.

A nav form only 'holds' one form at a time. When you choose a new tab, you close the form that's currently in view. Closing a form is one of the actions that commits a record that doesn't violate any validation rules, so you cannot simply undo, at least not without intervention.

To work around this, you'd have to put validation code in the form Unload event and cancel the unload if validation fails. Your close button Click event could simply be
DoCmd.Close
which would call the Unload event automatically because Unload occurs before Close event. If validation fails, you Cancel the unload event. However, in the click event, you'll have to handle error 2501 ("the close event was canceled") so as to not present that to the user. The reason for this approach would be that the Unload event can be canceled, but the Close event cannot.

BTW, it has oft been written that RunCommand should be used rarely, although I can't recall why. It's one of those things that if you never use it, you forget why not.
 
Last edited:
Upvote 0
I don't understand the question. As I mentioned, if we're talking about a navigation form, the form is loaded into the nav form when you click on the tab for the form you want to see. When you select a different tab, the current form is closed and the next chosen one opens. Whatever you've designed to have happen when those forms open or close will happen. If you want to have something happen before a form is chosen, you'll have to provide for that. If you don't want a form to be able to be opened before that point, you'll need a marker/flag/condition that tells Access not to allow the form to be opened. It seems your issue is expanding quite a bit from your originally posted question?
 
Upvote 0
I've never used a nav form that I didn't build myself and after reading about their issues, probably never will. Thus I can only make observations based on that, and since you've had 90 views with no replies, I'll share what little I know about them.

Thank you for taking the time and sorry for late answer, I left the project on hold for some time. I opted for my own starting form as it gave me more control and since I am not sure what I will add in 1 month. I don't formally ban navigation form but will avoid it nearly all the time for that reason.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,215
Members
448,554
Latest member
Gleisner2

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