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