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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tab Control Dirty 2

Status
Not open for further replies.

DanGriffin

Programmer
Jun 18, 2001
15
0
0
US
I have a form with a Tab Control consisting of 4 pages. All of the controls are on the pages. There are no controls on the form itself. And I suppose that's why this makes sense: Testing for ME.DIRTY is always false. And trying to test for ME!PAGE2.DIRTY triggers an error.

How do I test for unsaved data on a Tab Page?

I want the user to specifically SAVE or CANCEL any entered data before doing anything else. I have most everything covered except if the CLOSE the form with the 'X' button. (the form is maximized).

I was trying to test for DIRTY in the ON CLOSE event for the form.
 
Define a module level variable ImDirty of type Boolean

Then in the Form_OnDirty event set ImDirty = True
Form_Dirty event does respond when tab control fields are modified.


And then test for ImDirty in the Form_Unload event

( Remember to put ImDirty = False in On_Current etc or handle it in your other checking code.


QED?

G LS
 
Makes perfect sense. However, I don't see an event named DIRTY. I've checked the FORM properties, DETAIL properties and the TAB PAGE properties.

Suspecting that this might be an undocumented (Who!, Microsoft!) event, I went ahead with your suggestion and created the following sub in the module for the form in question...

Private Sub Form_Dirty()

bDirty = True

End Sub


... and set a breakpoint on the "bDirty = True" line. No matter what activity takes place in the form, this event never fires, and therefor never sets bDirty.

I have code that traps "Me.Dirty" in several places (such as record navigation) that work. However, I can't get anything to capture a DIRTY condition when the user uses the 'X' button to close the form. It's as if the Form's close button does not fire the OnClose event!?!?

When the form is closed in this manner the data that has been entered (without leaving the control) is saved WITHOUT any checking for validity (by the application). This is a problem!!
 
Why not stop the user from closing with the 'X'....either remove it from the form or write code to prevent the form from being closed unless the user clicks your close button....I have this code if you would like it... "As far as the laws of mathematics refer to reality, they are not certain; as far as they are certain, they do not refer to reality."--Albert Einstein [spin]

Robert L. Johnson III, A+, Network+, MCP
Access Developer/Programmer
 
The forms are maximised. Therefor, the 'X' button cannot be turned off. I sertainly would be interested in your code in any event.

I once saw some code somewhere that, in leu of maximising, resized the form to the size of the screen resolution using Windows API calls. It was a bit over my head at the time.

I'm sure I would learn something from whatever you offered.

Thsnks,
Dan
 
The Form On_Dirty event is listed immediately under the Form_AfterUpdate event.

Have another look - I think this will solve your immediate problems .. ..


.. .. but there is no substitute for a thorough understanding of the entire set of Windows API calls ( not! )



G LS
 
The code is pretty simple...

In the Declarations section of your form place

Dim OKToClose As Boolean

In the OnOpen event of the form place...

OKToClose = False

In the OnUnload of your Forms place

Cancel = Not OKToClose

And then in the code of your close button, merely set the OKToClose to True

OKToClose = True "As far as the laws of mathematics refer to reality, they are not certain; as far as they are certain, they do not refer to reality."--Albert Einstein [spin]

Robert L. Johnson III, A+, Network+, MCP
Access Developer/Programmer
 
In another thread I saw some references to "Form On_Dirty" in regards to Access 2000. I failed to mention that I am using Access 97.

I just tried mstrmage1768's suggestion which seems to effectively disable the the Form's CLOSE button as well as the Access Close button! It doesn't get rid of the button, it just makes them non-operational.

A simple and effective solution. The best kind!

Great job guys! These forums have saved me a LOT of time and have taught me more, faster, than any book or class I have tried. And it's free!! It doesn't get any better than that.

Thanks,
Dan
 
Change your error checking to the Before Update event for the form. Before Update runs before the close event is activated and will check for dirty before you even attempt to change the record. Your error checking will work here as well if a savy user moves to another record (thus changing unqualified data).

Good Luck!
SATHandle :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top