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

Dirty

Status
Not open for further replies.

ZOR

Technical User
Jan 30, 2002
2,963
GB
I have a command button which terminates entering a new record being created. I put my code in where I think the record has started being created, ie the first field has data entered, its autotab is set to true and goes to the next control. Its then I hit a button with code as below. However it sometimes seems to remove/cancel the record and sometimes not. Using messageboxes I was trying to debug it but maybe I am using the event incorrectly? Thanks

In a button on_click
If Me.Dirty = True Then
MsgBox "Dirty"
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.SetWarnings True
Else
If Me.Dirty = False Then
MsgBox "Not Dirty"
End If: End If
 
I have just used PHV's syntax of Me.Newrecord, it seems to work evertime. Can someone confirm this is correct, thanks

If Me.NewRecord = True Then
' Do nothing
Else
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.SetWarnings True
End If
 
Code:
If Me.Dirty = True Then
    MsgBox "Dirty"
    DoCmd.SetWarnings False
    DoCmd.RunCommand acCmdDeleteRecord
    DoCmd.SetWarnings True
    Else
     [COLOR=red]If Me.Dirty = False Then[/color]
     MsgBox "Not Dirty"
     End If: End If
The second If statement is unnecessary. If it gets to that line of code, it is because the first If statement has already evaluated that Me.Dirty is not True, therefore it must be False.


You might try using acCmdUndo, rather than acCmdDeleteRecord, if you are trying to cancel a new record.


 
Howdy ZOR . . .

Also have a look at [blue]UnDo[/blue]. Confirming the code from [blue]PHV[/blue], you could just as well us the [blue]Dirty[/blue] property. Cleaning your code I get:
Code:
[blue]   If Me.Dirty = True Then
      MsgBox "Dirty!"
      DoCmd.SetWarnings False
      Me.[purple][b]Undo[/b][/purple] [green]'revert the record to No Data Entry![/green]
      DoCmd.SetWarnings True
   Else
      MsgBox "Not Dirty!"
   End If[/blue]


Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
I would use PHV's suggestion of Me.Newrecord

I use that a lot.
 
It all depends on what you are interested in. If you are only concerned about new records, the use NewRecord. If you are concerned about any type of edits whatsoever, whether on existing or new records, then use Dirty.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top