Solved

What event to use to determine changes were made on a form?

Posted on 2015-01-20
5
67 Views
Last Modified: 2015-01-21
I'm not sure the best way to do this but I want to incorporate functionality that when a user makes any changes to any data and then tries to exit/close the form without saving the changes, I want to be able to prompt them with a message letting them know this. I don't believe the TextChanged event would work because that would get flagged every time you just select a record to edit or view. What about the Validated Event?

Thanks!
0
Comment
Question by:BlakeMcKenna
  • 2
  • 2
5 Comments
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 40560693
Microsoft does not implemented a way to inform you that data has change over time so that you can inform the user that there is data on the form that has not yet been saved. If you want such functionality you must implement it yourself. What you can do is set a Boolean data type variable and every time the user changes a variable that needs to be saved to update the Boolean to true and before closing the form check the state of that variable. You will also need to set this variable to false every time you save the data so that the variable correctly reflects the true state of the form's data.
0
 

Author Closing Comment

by:BlakeMcKenna
ID: 40560698
Hi Fernando,

That's actually what I'm doing now...kinda old school. I just wondered if there was an Event that could be utilized for this purpose. Oh well, I'll keep doing it the old way.

Thanks!
0
 
LVL 40
ID: 40563278
This is how I do it, in a way that makes it easier to change the variable (_hasChanged). Note the Handles at the right of the event method declaration. This is the list of all the controls that contains information that needs to be saved in the database. I can thus set the variable from a unique point instead of doing it from many different places in the Form.
	Private Sub Type_Changed(sender As Object, e As EventArgs) Handles cboLocal.TextChanged, txtPlural.TextChanged, txtType.TextChanged, chkBuyUnit.CheckedChanged, chkList.CheckedChanged, chkManual.CheckedChanged, chkPerishable.CheckedChanged, chkSpecialLocation.CheckedChanged, chkWarning.CheckedChanged
		_hasChanged = True
	End Sub

Open in new window

0
 

Author Comment

by:BlakeMcKenna
ID: 40563319
James,

Did you declare Type using WithEvents?
0
 
LVL 40
ID: 40563716
Type is not declared, it is simply the name I gave to the method because the data comes from a Type table in the database.

Contrary to what many think, because that was the case in classic VB, the name of an event method does not matter. Call it ji67vL_oifje78 or ab if you want. What makes the method an event is the Handles at the end of the declaration. They are what really matters. The signature (parameters type) must also be of the right type for the events that you want to trap.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now