Prompt user to save a database entry if they navigate away without saving.

Hi Experts,

I have created a database win form app. using to hold basic customer info.

The user is presented with the form to fill and a save button to save the completed form.

I have also created video style buttons allowing the user to navigate through the database.

What I want to do is prompt the user to save the an unsaved database entry if they try to navigate away from it before saving.

I thought setting a save database flag in my code when a textbox textchanged event is triggered by an entry being made. The problem with this approach is that when the user is navigating through the database as the text changes to the next entry is triggers the event and thus prompting the user to save.

Is there a better way to do this?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jacques Bourgeois (James Burger)PresidentCommented:
There are different ways of doing that, depending on the technique that you use to display the information and update it.

If you do it with a DataTable linked to the controls with data binding, then you do not need your flag, because a DataTable handles the necessary information through its RowState property. It would be a better way of doing it than your flag.

If you fill the control yourself through your code, then simply reset your flag to False after the data is displayed for a new record.

If you use another technique, try to see if there is a property somewhere that tells you that the data has changed.

If you do not find a way to determine when a new record has been displayed, then you might start a Timer for a second or so when the user clicks on your button. Reset your flag when the timer triggers. Unless you have something that is very slow, 1 second will be sufficient for the data to display, but the user will not have time to click on your button and start changing data during that time.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.