Results 1 to 9 of 9
  1. #1
    Join Date
    Jul 2004
    Posts
    156

    Unanswered: How to Undirty a record

    Hello all:

    I'm having some troubles understanding the Dirty event and its Cancel option. What I'm needing to do is, on close, have the form undo any current changes to the new record so that they're not saved on close. From what I've read, it seems that the Dirty event can be cancelled and anything added since first dirtying can be cleaned.

    Can someone help out? Thanks a million!

    UPDATE: I tried using the form.Undo method and this doesn't work because if they hit the "X" to close it, it updates the record before closing. I guess I'll try the Unload or other similar event.
    Last edited by DocX; 08-02-04 at 17:15.
    DocX

    The teachings of God's Begotten: 2 John 1:9

  2. #2
    Join Date
    Apr 2002
    Location
    Illinois
    Posts
    133
    Check out the index under Help for Dirty and OldValue properties.

    Here's an example to help.

    Sub UndoEdits()
    If Me.Dirty Then
    Me!btnUndo.Enabled = True ' Enable button.
    Else
    Me!btnUndo.Enabled = False ' Disable button.
    End If
    End Sub

    Sub btnUndo_Click()
    Dim ctlC As Control
    ' For each control.
    For Each ctlC in Me.Controls
    If ctlC.ControlType = acTextBox Then
    ' Restore Old Value.
    ctlC.Value = ctlC.OldValue
    End If
    Next ctlC
    End Sub
    SteveH

  3. #3
    Join Date
    Jun 2004
    Location
    Florida, US
    Posts
    521
    Only workaround of this porblem I know is disabling the X (close) button on form and and offer your own Cancel and OK buttons. which you can undo and exit when cancel clicked, or you can save data if OK clicked.
    for cancel button:
    Code:
      
      if me.dirty then me.undo
      docmd.close
    for OK button:
    Code:
      
      if me.dirty then me.dirty=false
      docmd.close
    ghozy.

  4. #4
    Join Date
    Jul 2004
    Posts
    156
    Thanks, ghozy.

    I had thought of this resolution, but the only problem with it is that they can close the window by right-clicking on the taskbar window and selecting close that way. That leaves an unchecked record in the main records. I'm not really sure how to incorporate the Undo with the close events (unload, close, etc.) because it's already tried to update before that happens. :-\
    DocX

    The teachings of God's Begotten: 2 John 1:9

  5. #5
    Join Date
    Jun 2004
    Location
    Florida, US
    Posts
    521
    maybe this article would help your problem. it is about disbaling close button of form.
    http://www.tek-tips.com/gfaqs.cfm/le...d/702/fid/2071
    ghozy.

  6. #6
    Join Date
    Jul 2004
    Posts
    156
    I believe this would work if I wanted to place a button on the form that they had to use to close the form. However, I'd prefer for them to not lose the freedom and ease of just closing the form with the "X" or right-clicking the taskbar. Unload and Close events occur AFTER the new record has been formed.

    I'm trying to catch the spot between where you click on the "X" to close it and when it adds/updates the new record. If anyone could help me on that, I'd greatly appreciate it.
    DocX

    The teachings of God's Begotten: 2 John 1:9

  7. #7
    Join Date
    Jun 2004
    Location
    Florida, US
    Posts
    521
    sorry I'm out of ideas.
    ghozy.

  8. #8
    Join Date
    Jul 2004
    Posts
    156
    Hey, ghozy, or anyone else interested for that matter:

    I've chosen to do the close button using the method introduced at that link you sent. Works great.

    I tried using the same idea to prevent an Update to happen by declaring an AllowSave and if this was False, then it would Cancel the BeforeUpdate event. However, it seems to be half working. I have set up exactly like the AllowClose.

    Declare public AllowSave variable as Boolean.
    Put in Form_Load, AllowSave = False.
    In Save button's Click event, AllowSave = True.
    Then, in BeforeUpdate, Cancel = Not AllowSave at the beginning of the event.

    It cancels the updating of the record but keeps going with the other statements in the BeforeUpdate procedure. Got any tips? Need more clarification, just ask! Thanks!
    DocX

    The teachings of God's Begotten: 2 John 1:9

  9. #9
    Join Date
    Sep 2004
    Posts
    1
    Opps, Newbie
    Last edited by rw_ga; 10-21-04 at 14:39.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •