Solved

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

Posted on 2015-01-20
5
73 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

622 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