473,748 Members | 8,367 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dirty Event for Form is not "firing".

I am currently using the OnDirty event of a Form to detect whether any
fields have been modified. I set a boolean variable. Then, if the
Close button is clicked before the Save button, I can put up a message
on the screen that will tell the user that "Data has been changed, do
you wish to Save the record before Closing this window?"

I think I've just discovered this only works if the record that is being
displayed/modified it not a NewRecord.

How should I deal with the situation when the User is working on a
NewRecord and (supposedly) has filled in all the required fields and
then hits the Close Button before hitting the Save button?

Regards,
SueB

*** Sent via Developersdex http://www.developersdex.com ***
Nov 13 '05 #1
9 15857
In some versions of Access, the form's Dirty event will not fire if the
record is dirtied programmaticall y.

For example, if you assign a value to a bound control in the Current event
of the form, its Dirty event will not fire.

Is there are need to use this event to manage your own variable? The form
already has a dirty property, so you could code:
If Me.Dirty Then ...

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Susan Bricker" <sl*****@verizo n.net> wrote in message
news:YW******** *********@news. uswest.net...
I am currently using the OnDirty event of a Form to detect whether any
fields have been modified. I set a boolean variable. Then, if the
Close button is clicked before the Save button, I can put up a message
on the screen that will tell the user that "Data has been changed, do
you wish to Save the record before Closing this window?"

I think I've just discovered this only works if the record that is being
displayed/modified it not a NewRecord.

How should I deal with the situation when the User is working on a
NewRecord and (supposedly) has filled in all the required fields and
then hits the Close Button before hitting the Save button?

Nov 13 '05 #2
Allen Browne wrote:
In some versions of Access, the form's Dirty event will not fire if the
record is dirtied programmaticall y.

For example, if you assign a value to a bound control in the Current event
of the form, its Dirty event will not fire.

Is there are need to use this event to manage your own variable? The form
already has a dirty property, so you could code:
If Me.Dirty Then ...

Hi Allen. I think this situation can be examined easily. I created a
table called Table1. It contained 3 fields
ID; Autonumber
Test1; Text
Test2; Text.

I created a form using the wizard for Table1.

I then dropped the code below into it. You can't stop new record loss
as near as I can determine. Try it out with only new records first.
Go to a new record
In field Test1 (less than 4 chars to fire BeforeUpdate Cancel)
Tab to field Test2.
Now click on the X button.

There is no way I can see that you can stop a New Record that may
contain some data from being lost.

Option Compare Database
Option Explicit
Dim intMouseCnt As Integer
Dim blnX As Boolean
Private Sub Form_AfterUpdat e()
MsgBox "After Update"
End Sub
Private Sub Form_BeforeUpda te(Cancel As Integer)
If Len(Me.Test1) < 4 Then
MsgBox "Less 4"
Cancel = True
End If
End Sub
Private Sub Form_Close()
MsgBox "Close"
End Sub
Private Sub Form_Deactivate ()
MsgBox "Deactivate Dirty " & Me.Dirty
MsgBox "Deactivate New Record " & Me.NewRecord
MsgBox "Deactivate test1 = " & Me.Test1

End Sub
Private Sub Form_Error(Data Err As Integer, Response As Integer)
MsgBox "Error Dataerr " & DataErr
MsgBox "Error Dirty " & Me.Dirty
MsgBox "Error New Record " & Me.NewRecord
MsgBox "Error test1 = " & Me.Test1

'No can do
'If DataErr = 2169 Then Me.Dirty = False

Response = acDataErrContin ue
End Sub
Private Sub Form_Unload(Can cel As Integer)
If Not blnX Then
MsgBox "Unload Dirty " & Me.Dirty
MsgBox "Unload New Record " & Me.NewRecord
MsgBox "Unload test1 = " & Me.Test1

'Cancel does absolutely nothing because the code
'doesn't even execute before the new record
'with data is wiped out.
Cancel = True
blnX = True
End If
End Sub
Nov 13 '05 #3
No idea how that relates to the OP's q.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Salad" <oi*@vinegar.co m> wrote in message
news:6n******** ********@newsre ad1.news.pas.ea rthlink.net...
Allen Browne wrote:
In some versions of Access, the form's Dirty event will not fire if the
record is dirtied programmaticall y.

For example, if you assign a value to a bound control in the Current
event of the form, its Dirty event will not fire.

Is there are need to use this event to manage your own variable? The form
already has a dirty property, so you could code:
If Me.Dirty Then ...

Hi Allen. I think this situation can be examined easily. I created a
table called Table1. It contained 3 fields
ID; Autonumber
Test1; Text
Test2; Text.

I created a form using the wizard for Table1.

I then dropped the code below into it. You can't stop new record loss as
near as I can determine. Try it out with only new records first.
Go to a new record
In field Test1 (less than 4 chars to fire BeforeUpdate Cancel)
Tab to field Test2.
Now click on the X button.

There is no way I can see that you can stop a New Record that may contain
some data from being lost.

Option Compare Database
Option Explicit
Dim intMouseCnt As Integer
Dim blnX As Boolean
Private Sub Form_AfterUpdat e()
MsgBox "After Update"
End Sub
Private Sub Form_BeforeUpda te(Cancel As Integer)
If Len(Me.Test1) < 4 Then
MsgBox "Less 4"
Cancel = True
End If
End Sub
Private Sub Form_Close()
MsgBox "Close"
End Sub
Private Sub Form_Deactivate ()
MsgBox "Deactivate Dirty " & Me.Dirty
MsgBox "Deactivate New Record " & Me.NewRecord
MsgBox "Deactivate test1 = " & Me.Test1

End Sub
Private Sub Form_Error(Data Err As Integer, Response As Integer)
MsgBox "Error Dataerr " & DataErr
MsgBox "Error Dirty " & Me.Dirty
MsgBox "Error New Record " & Me.NewRecord
MsgBox "Error test1 = " & Me.Test1

'No can do
'If DataErr = 2169 Then Me.Dirty = False

Response = acDataErrContin ue
End Sub
Private Sub Form_Unload(Can cel As Integer)
If Not blnX Then
MsgBox "Unload Dirty " & Me.Dirty
MsgBox "Unload New Record " & Me.NewRecord
MsgBox "Unload test1 = " & Me.Test1

'Cancel does absolutely nothing because the code
'doesn't even execute before the new record
'with data is wiped out.
Cancel = True
blnX = True
End If
End Sub

Nov 13 '05 #4
Allen Browne wrote:
No idea how that relates to the OP's q.


I may have misunderstood the following:
"How should I deal with the situation when the User is working on a
NewRecord and (supposedly) has filled in all the required fields and
then hits the Close Button before hitting the Save button?"

I figured the Close button is the X button on the form's caption bar
next to the Min/Restore buttons instead of a oommand button on the form
with the caption Close. It a user presses the X (close) button a
BeforeUpdate event will fire but is ignored and unless the record
already exists (not an newrecord) it will be lost.

Nov 13 '05 #5
Salad <oi*@vinegar.co m> wrote in
news:g0******** *******@newsrea d2.news.pas.ear thlink.net:
Allen Browne wrote:
No idea how that relates to the OP's q.


I may have misunderstood the following:
"How should I deal with the situation when the User is working on
a NewRecord and (supposedly) has filled in all the required fields
and then hits the Close Button before hitting the Save button?"

I figured the Close button is the X button on the form's caption
bar next to the Min/Restore buttons instead of a oommand button on
the form with the caption Close. It a user presses the X (close)
button a BeforeUpdate event will fire but is ignored and unless
the record already exists (not an newrecord) it will be lost.


But this is a classic known bug and it is handled by forcing the
save in the form's OnClose event, or getting rid of the form's Close
button and supplying your own that forces Me.Dirty = False before
closing the forme, which should throw errors if there are required
fields not filled out.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #6
David W. Fenton wrote:
Salad <oi*@vinegar.co m> wrote in
news:g0******** *******@newsrea d2.news.pas.ear thlink.net:

Allen Browne wrote:
No idea how that relates to the OP's q.


I may have misunderstood the following:
"How should I deal with the situation when the User is working on
a NewRecord and (supposedly) has filled in all the required fields
and then hits the Close Button before hitting the Save button?"

I figured the Close button is the X button on the form's caption
bar next to the Min/Restore buttons instead of a oommand button on
the form with the caption Close. It a user presses the X (close)
button a BeforeUpdate event will fire but is ignored and unless
the record already exists (not an newrecord) it will be lost.

But this is a classic known bug and it is handled by forcing the
save in the form's OnClose event, or getting rid of the form's Close
button and supplying your own that forces Me.Dirty = False before
closing the forme, which should throw errors if there are required
fields not filled out.


Hmmmm...I wonder if this bug will be removed in the new version of
Access. Perhaps it's been around so long it's considered a feature.

The problem that I see is that the form has "unloaded" prior to hitting
the OnClose event and if a BeforeUpdate event occurred that Canceled,
the reset of the Autonumber/NewRecord will occur prior to that Close event.

Maybe by using a Type/EndType construct in the OnError event to ask the
user whether or not to save could work by canceling the Unload and
refilling the fields.
Nov 13 '05 #7
Salad <oi*@vinegar.co m> wrote in
news:HD******** ********@newsre ad1.news.pas.ea rthlink.net:
David W. Fenton wrote:
Salad <oi*@vinegar.co m> wrote in
news:g0******** *******@newsrea d2.news.pas.ear thlink.net:

Allen Browne wrote:

No idea how that relates to the OP's q.

I may have misunderstood the following:
"How should I deal with the situation when the User is working ona NewRecord and (supposedly) has filled in all the required
fields and then hits the Close Button before hitting the Save
button?"

I figured the Close button is the X button on the form's caption
bar next to the Min/Restore buttons instead of a oommand button
on the form with the caption Close. It a user presses the X
(close) button a BeforeUpdate event will fire but is ignored and
unless the record already exists (not an newrecord) it will be
lost.

But this is a classic known bug and it is handled by forcing the
save in the form's OnClose event, or getting rid of the form's
Close button and supplying your own that forces Me.Dirty = False
before closing the forme, which should throw errors if there are
required fields not filled out.


Hmmmm...I wonder if this bug will be removed in the new version

of Access. Perhaps it's been around so long it's considered a
feature.

The problem that I see is that the form has "unloaded" prior to
hitting the OnClose event and if a BeforeUpdate event occurred
that Canceled, the reset of the Autonumber/NewRecord will occur
prior to that Close event.

Maybe by using a Type/EndType construct in the OnError event to
ask the user whether or not to save could work by canceling the
Unload and refilling the fields.


Seems to me it's just much easier to avoid using the built-in close
button, and just write your own code that won't close the form
until
you know the record has been saved in a proper state.

That's the way I approach deleting records -- I never allow
deletions through the Access UI, because you cam't depend on the
OnDeleteConfirm event to fire (if SetWarnings is off) and because
by
the time it fires, the record is already gone, so you're forced to
cache the data *before* the delet in order to provide a meaningful
"Do you want to delete the record for 'David W. Fenton"?"
confirmation message.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #8
David W. Fenton wrote:
Salad <oi*@vinegar.co m> wrote in
news:HD******** ********@newsre ad1.news.pas.ea rthlink.net:

David W. Fenton wrote:
Salad <oi*@vinegar.co m> wrote in
news:g0***** **********@news read2.news.pas. earthlink.net:

Allen Browne wrote:
>No idea how that relates to the OP's q.

I may have misunderstood the following:
"How should I deal with the situation when the User is working
on
a NewRecord and (supposedly) has filled in all the required
fields and then hits the Close Button before hitting the Save
button?"

I figured the Close button is the X button on the form's caption
bar next to the Min/Restore buttons instead of a oommand button
on the form with the caption Close. It a user presses the X
(close) button a BeforeUpdate event will fire but is ignored and
unless the record already exists (not an newrecord) it will be
lost.
But this is a classic known bug and it is handled by forcing the
save in the form's OnClose event, or getting rid of the form's
Close button and supplying your own that forces Me.Dirty = False
before closing the forme, which should throw errors if there are
required fields not filled out.

Hmmmm...I wonder if this bug will be removed in the new version


of
Access. Perhaps it's been around so long it's considered a
feature.

The problem that I see is that the form has "unloaded" prior to
hitting the OnClose event and if a BeforeUpdate event occurred
that Canceled, the reset of the Autonumber/NewRecord will occur
prior to that Close event.

Maybe by using a Type/EndType construct in the OnError event to
ask the user whether or not to save could work by canceling the
Unload and refilling the fields.

Seems to me it's just much easier to avoid using the built-in close
button, and just write your own code that won't close the form
until
you know the record has been saved in a proper state.


So many people are used to the min/max/close window buttons that yes, a
form without a close button can be used but I like giving ops whatever
options they want.

If MS knows about this, I think enough versions have gone by that they
can fix it.

That's the way I approach deleting records -- I never allow
deletions through the Access UI, because you cam't depend on the
OnDeleteConfirm event to fire (if SetWarnings is off) and because
by
the time it fires, the record is already gone, so you're forced to
cache the data *before* the delet in order to provide a meaningful
"Do you want to delete the record for 'David W. Fenton"?"
confirmation message.

Hmmm....I Cancel deletes if the op declines. I've not experienced this
issue.
Nov 13 '05 #9
Salad <oi*@vinegar.co m> wrote in
news:LN******** *********@newsr ead3.news.pas.e arthlink.net:
David W. Fenton wrote:
[]
Seems to me it's just much easier to avoid using the built-in
close button, and just write your own code that won't close the
form until
you know the record has been saved in a proper state.


So many people are used to the min/max/close window buttons that
yes, a form without a close button can be used but I like giving
ops whatever options they want.


You can fake a title bar and a close button. I think the Marlett
font comes with all versions of Outlook and/or Office, and it has
an
X that works great for replicating the x button. The close button
on
each these forms:

http://www.dfenton.com/DFA/examples/assignment.gif
http://www.dfenton.com/DFA/examples/c_1summ.gif
http://www.dfenton.com/DFA/examples/Activities.gif

is fake. That's how I got the custom-looking titlebar.
If MS knows about this, I think enough versions have gone by that
they can fix it.


I think the reliability of forms as editing tools started a general
decline with the release of A2K.
That's the way I approach deleting records -- I never allow
deletions through the Access UI, because you cam't depend on the
OnDeleteConfirm event to fire (if SetWarnings is off) and because by
the time it fires, the record is already gone, so you're forced
to cache the data *before* the delet in order to provide a
meaningful "Do you want to delete the record for 'David W.
Fenton"?" confirmation message.


Hmmm....I Cancel deletes if the op declines. I've not

? experienced this issue.

But if SetWarnings is off, the OnDeleteConfirm event never happens.
If it does and you set Cancel = True, then the record reappears,
when it was previously gone.

Both of these are things I consider unacceptable in a
professional-looking application, so I avoid them entirely by not
using any of the delete events.

I believe that is also the solution for the default values problem.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
2972
by: sara | last post by:
Hi I'm pretty new to Access here (using Access 2000), and appreciate the help and instruction. I gave myself 2.5 hours to research online and help and try to get this one, and I am not getting it. Simple database: I want to have a user enter Supply Orders (just for tracking purposes) by Item. The user may also enter a new item - "new" is a combination of Item, PartNumber and Vendor - they could have the
14
5918
by: dale zhang | last post by:
Hi groups, Can anyone give me the equivalent C# sharp code for this VB.ET code, :: VB.NET :: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles MyBase.Load 'This event routine in the loginCheck user control fires when the
1
1877
by: Holger (David) Wagner | last post by:
Hi there, we have an application which is built with several ASCX controls some of which contain form elements (e.g. Textboxes, Buttons etc.) For example: in the top section (one ascx-control), there is a textbutton in which the user can enter a string to search for. There's link button right next to that textbutton. Then, in the "content section" (another ascx-control), there may be a login-dialog which prompts the user for...
3
1786
by: cmay | last post by:
In reading some documents from the Patterns and Practices group, I had a question about the example given for the Page Controller pattern. (I have posted the code for the BasePage below) In short, their example shows a "BasePage " class for other pages to inherit from. The subclasses are supposed to implement the PageLoadEvent method (which I guess should really be abstract, but can't because asp.net
15
2927
by: Billy | last post by:
Anyone know if this a bug in VB.NET 2002 and how to overcame that situation? I have a MDI form from where I call MDI child form like that: Dim frm As New frmChild() frm.MdiParent = Me frm.Show() On that child form I have some textboxes. When form show up Leave event
16
1827
by: abc my vclass | last post by:
C# has VB's "with" command? I like VB's with command, why don't know C# has it or not?
15
6021
by: cedmunds | last post by:
Group: We have an application that is calling a stored proc. The stored proc takes anywhere from 15 to 90 minutes to run. In order to keep the GUI responsive, we are using a BackgroundWorker to actually make the call to the stored proc. The app then sits in a loop that awakes every second and updates an elapsed time value. The problem that we are having is that after a certain period of time -
8
2282
by: timor.super | last post by:
Hi group, I would like to simulate something that can be quite similar to "Events". I would like that a member function of a class can be "setted" as an Event and that this method can be called after something special. Consider the following example : I'm setting a function with a pointor function, then in a while-true block, I ask for an input, if input is "abc", i'm firing an event (that prints "abc").
9
5567
Basharat
by: Basharat | last post by:
Hi all I have problem on firing "onmouseleave" event of <div> html element. Here is the code im using: <div ID="BSHelpPanel" class="PageMenuMain" onclick="javascript:this.style.display='none';" runat="server" > its working fine in IE while some other events too are not firing in firefox like ondeactivate onfocusout etc.
0
8984
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8823
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9530
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9363
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8237
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4593
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2206
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.