Solved

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

Posted on 2015-01-20
5
72 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
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 …
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

729 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