Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Check if Form is Dirty (data changed)

Status
Not open for further replies.

knuckle05

Programmer
Joined
Dec 17, 2001
Messages
247
Location
CA
Hi All,

I have a form with many data entry controls on it (about 40) and they are unbound. I'm wondering if anyone knows of a way to check if the form isDirty before I call a Cancel routine.

I've thought about setting a boolean var but this seems tedious to do for every control. Are there any API's that may help. So far I have not found an easy way out. Any suggestions would be much appreciated. Thanks
 

A single boolean value declared at form level and if your textboxes are part of an array then all you would need to do is set the boolean value in the change event. Although when navigating records you will have to reset the boolean value after populating the textboxes.

I had previously thought about the form and setting its keypreview property to true and setting a boolean value there but even if a commandbutton has the focus the value would be set even though no data has been changed, so that won't work for you.
 
I guess I should have made my textboxes part of an array (they are not).

I like the idea of the KeyPreview. Maybe I could check the TYPE of control (ie command button). I'll try that. Thanks
 
I'm not sure that using KeyPreview is the wisest approach, depending upon the criteria to determine when the form is dirty. If a user were to use the arrow keys to scroll thru a grid, or a list box, and so forth will generate KeyPreview events, but would not necessarily constitutate "dirtying" the form. I think that vb5prgrmr suggestion by using the Change event is quite worthy of consideration with some, if not most types of controls, but not all. You may also have some text boxes which are display only, used in such a way that the display would change, without the form becoming dirty. Check Boxes and Radio Buttons for example would have to handled differently. As previously stated, Command buttons being pressed in an of themselves would not cause a form to become dirty, but the actions taken as a result of the press may.

Another approach may be to place the original value of any control in the Tag field of that control. You can then walk thru each control, comparing the current value with the Tag value to see if that control has changed before you call the cancel routine. That of course assumes that your controls all have Tag properties.

There are several approaches and its hard to recommend any one without more understanding of the form and its functionality. Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top