Results 1 to 11 of 11
  1. #1
    gg80 is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Posts
    328

    OnDirty Cancel

    I am using A2003 an A2007. Working with a single form. I am trying to do this:

    If onDirty Then
    Perform some action
    Me.Dirty=False ‘so can do same action if this SAME record is again “dirtied” (reset timer in this case)
    End if

    Apparently, you can’t reset onDirty without leaving the record and returning. Is there a way to reset onDirty after the first onDirty event in the same record?

    In this particular case, the user wants the form to be locked if no changes have been made for X minutes. (He is afraid of someone inadvertently making a change with their elbow, pencil or whatever while working on other things at one of the desks)



    A better way than what I am trying? Any help much appreciated.

  2. #2
    Beetle is offline Unrelatable
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    Camp Swampy (Denver, CO)
    Posts
    207
    You can find code to detect idle time or inactivity at this link. You could just lock the form after X amount of time and include a command button to unlock it.

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    You can reset Dirty without leaving the Form, with a simple

    If Me.Dirty then Me.Dirty = False

    or even

    DoCmd.RunCommand acCmdSaveRecord

    but you can't do it from the OnDirty event!

    But to be honest, if a pencil hits the keyboard, or an errant elbow, or a flying squirrel, how is locking the Form, after X amount of idle time, going to prevent this, or even make them aware that it occurred?

    What you really need to do is to use validation code to ask the user what they want to do, if a Form has been Dirtied, i.e had data entered or data edited, when they try to leave the Record, close the Form or close Access, itself. At this point the Form_BeforeUpdate event fires, so ask them if they want to save or dump the New Record or the changes to an existing Record:
    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    If Not (Me.NewRecord) Then
      If MsgBox("Would You Like To Save The Changes To This Record?", vbQuestion + vbYesNo + vbDefaultButton1, "Save Changes to Record ???") = vbNo Then
       Me.Undo
      End If
    Else
      If MsgBox("Would You Like To Save This New Record?", vbQuestion + vbYesNo + vbDefaultButton1, "Save This New Record ???") = vbNo Then
       Me.Undo
      End If
    End If
    End Sub


    This will at least remind them to check the data, one last time, before the Record is saved.

    If you just have to lock the Form after X amount of time, Sean's approach is the correct one, but it's not going to guarantee that data won't be accidentally changed.

    Linq ;0)>

  4. #4
    gg80 is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Posts
    328
    Thanks for quick action. I'm afraid that I couldn't get much out of the link that you listed. Like many of the microsoft "how tos", they are written for pros like you and not for amateurs like me. There is always critical knowledge assumed, steps left out, etc.. I wonder sometimes why they bother,- it seems like those who can understand and use it probably don't need it. I just couldn't assemble anything that did anything. Like-how communicate with form "DetectTime" and the form I'm trying to monitor? I will try again, but not much hope. Though it doesn't quite fill the need, I will go with your other suggestion. Thanks again for taking your time with this.

  5. #5
    Beetle is offline Unrelatable
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    Camp Swampy (Denver, CO)
    Posts
    207
    If you have questions about how to implement the code in the link feel free to ask.

  6. #6
    gg80 is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Posts
    328
    I played with it. From the description, I assumed that the provided code would monitor another open form in the program. I tried it and it only monitors the DetctedTime form. So, do I put that code in any form that I want to be monitored for inactivity or am I doing something wrong.? Thanks much.

  7. #7
    gg80 is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Posts
    328
    The validation code works well. I will propose that and Sean's solution, to the user. The OndDrty thing still eludes me. If not in the OnDirty event. where do I put code statement "docmd.runcmd accmdsaveReport" or "if dirty then me.dirty=false." On each updateable control UfterUpdate?

  8. #8
    gg80 is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Posts
    328
    The validation code works well. I will propose that and Sean's solution, to the user. The OndDrty thing still eludes me. If not in the OnDirty event. where do I put code statement "docmd.runcmd accmdsaveReport" or "if dirty then me.dirty=false." On each updateable control UfterUpdate
    Quote Originally Posted by Missinglinq View Post
    You can reset Dirty without leaving the Form, with a simple

    If Me.Dirty then Me.Dirty = False

    or even

    DoCmd.RunCommand acCmdSaveRecord

    but you can't do it from the OnDirty event!

    But to be honest, if a pencil hits the keyboard, or an errant elbow, or a flying squirrel, how is locking the Form, after X amount of idle time, going to prevent this, or even make them aware that it occurred?

    What you really need to do is to use validation code to ask the user what they want to do, if a Form has been Dirtied, i.e had data entered or data edited, when they try to leave the Record, close the Form or close Access, itself. At this point the Form_BeforeUpdate event fires, so ask them if they want to save or dump the New Record or the changes to an existing Record:
    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    If Not (Me.NewRecord) Then
      If MsgBox("Would You Like To Save The Changes To This Record?", vbQuestion + vbYesNo + vbDefaultButton1, "Save Changes to Record ???") = vbNo Then
       Me.Undo
      End If
    Else
      If MsgBox("Would You Like To Save This New Record?", vbQuestion + vbYesNo + vbDefaultButton1, "Save This New Record ???") = vbNo Then
       Me.Undo
      End If
    End If
    End Sub


    This will at least remind them to check the data, one last time, before the Record is saved.

    If you just have to lock the Form after X amount of time, Sean's approach is the correct one, but it's not going to guarantee that data won't be accidentally changed.

    Linq ;0)>

  9. #9
    gg80 is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Posts
    328

    inactivity detect

    Quote Originally Posted by Beetle View Post
    If you have questions about how to implement the code in the link feel free to ask.
    I got it working. I tried different things, but can't figure out the next step. That is, how do I tell it to lock the form after the time limit.?

  10. #10
    gg80 is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Posts
    328
    Thanks-Works. I do have one form with a subform and found out how that makes things much much more complicated, but can handle it. I cannot make the " if me.dirty then me.dirty = false" work. Exactly where do you put the statement.

    I am going to give my user a choice of this solution and Sean's solution as soon as I get it working. I willl mark as solved then.

  11. #11
    gg80 is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Posts
    328
    figured it out-thanks for all. Solved


    Quote Originally Posted by gg80 View Post
    I got it working. I tried different things, but can't figure out the next step. That is, how do I tell it to lock the form after the time limit.?

Please reply to this thread with any new information or opinions.

Similar Threads

  1. onDirty Code
    By tariq1 in forum Programming
    Replies: 2
    Last Post: 08-11-2012, 01:27 PM
  2. Cancel Error
    By Newbie11 in forum Reports
    Replies: 1
    Last Post: 02-13-2012, 09:13 AM
  3. Yes/No/Cancel Message Box
    By lynnmc26 in forum Access
    Replies: 0
    Last Post: 04-01-2011, 07:26 PM
  4. VBA to cancel a macro
    By GraemeG in forum Programming
    Replies: 1
    Last Post: 03-26-2011, 04:50 PM
  5. Cancel new record
    By oakoen in forum Forms
    Replies: 11
    Last Post: 12-18-2010, 09:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums