Solved

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

Posted on 2015-01-20
5
70 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 63

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …

840 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