Results 1 to 7 of 7
  1. #1
    tylerg11 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2011
    Posts
    200

    Dirty property for Text Box

    Here is my scenario:

    I have a textbox on my form, that when modified (or dirty), should also force the user to update a second textbox. How can I code this?



    So, if TextBox1 and TextBox2 are Dirty, save the record (or do not cancel the update). But if only TextBox1 has been modified, alert the user to update TextBox2, and cancel the update until they are both "Dirty". I know this has a lot to do with the Dirty property, but I do I use this property at the field/textbox level, instead of the form level?

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You need to do your validation in the FORM's BeforeUpdate event.

  3. #3
    tylerg11 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2011
    Posts
    200
    That's how I have it. But how do I refer to the Dirty property of specific fields. For example, I want to see if two of the many textboxes are "dirty".

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Only the FORM has a Dirty property because it is the RECORD that is dirty not a bound control on the form. Does that help?

  5. #5
    tylerg11 is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2011
    Posts
    200
    Yes. Thanks.

    Is it possible to check if a textbox has been modified or edited? Even if the new value entered is the same?

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Almost. There is a .OldValue property of bound controls that can be compared to the .Value property. If the value entered is the same then it will compare but the Dirty property will still be set. Depending on how critical this issue is, you may want to implement your own ControlDirty property using the Change event of the control and maybe the Tag property of the same control.

  7. #7
    Cloudster is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2015
    Posts
    1

    Thanks, RuralGuy!

    Your info got me pointed in the right direction. I wanted to prevent accidental modification of a key field, it isn't the PK of the record but is still quite important. I came up with the following code that does the trick quite well:

    Code:
    Private Sub STARSID_LostFocus()
        'can't directly check for .Dirty, must compare to .OldValue
        With STARSID
            If .Value <> .OldValue Then
                retval = MsgBox("You have changed the STARS ID.  Did you mean to do this?  Selecting No will reset it to the original value.", vbYesNo)
                If retval = vbNo Then .Value = .OldValue
            End If
        End With
    End Sub
    I'm tempted to clear Dirty for the form, but the user might have changed other fields.

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

Similar Threads

  1. Me.Dirty not catching
    By Ashe in forum Forms
    Replies: 4
    Last Post: 10-27-2011, 11:30 AM
  2. Replies: 7
    Last Post: 10-03-2011, 12:44 PM
  3. On Dirty fires but Me.Dirty = False (v2010)
    By Rod in forum Programming
    Replies: 5
    Last Post: 07-30-2011, 08:42 PM
  4. Dirty
    By JEPEDEWE in forum Programming
    Replies: 1
    Last Post: 11-13-2010, 04:50 PM
  5. Delete and Dirty functions
    By Evgeny in forum Programming
    Replies: 3
    Last Post: 05-03-2010, 02:39 PM

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