473,397 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

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 15816
In some versions of Access, the form's Dirty event will not fire if the
record is dirtied programmatically.

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*****@verizon.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 programmatically.

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_AfterUpdate()
MsgBox "After Update"
End Sub
Private Sub Form_BeforeUpdate(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(DataErr 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 = acDataErrContinue
End Sub
Private Sub Form_Unload(Cancel 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.com> wrote in message
news:6n****************@newsread1.news.pas.earthli nk.net...
Allen Browne wrote:
In some versions of Access, the form's Dirty event will not fire if the
record is dirtied programmatically.

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_AfterUpdate()
MsgBox "After Update"
End Sub
Private Sub Form_BeforeUpdate(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(DataErr 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 = acDataErrContinue
End Sub
Private Sub Form_Unload(Cancel 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.com> wrote in
news:g0***************@newsread2.news.pas.earthlin k.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.com> wrote in
news:g0***************@newsread2.news.pas.earthlin k.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.com> wrote in
news:HD****************@newsread1.news.pas.earthli nk.net:
David W. Fenton wrote:
Salad <oi*@vinegar.com> wrote in
news:g0***************@newsread2.news.pas.earthlin k.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.com> wrote in
news:HD****************@newsread1.news.pas.earthli nk.net:

David W. Fenton wrote:
Salad <oi*@vinegar.com> wrote in
news:g0***************@newsread2.news.pas.earth link.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.com> wrote in
news:LN*****************@newsread3.news.pas.earthl ink.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
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...
14
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...
1
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...
3
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...
15
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...
16
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
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...
8
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...
9
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';"...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.