Access 97 question on change events

hammerva

Registered User.
Local time
Today, 16:01
Joined
Dec 19, 2000
Messages
102
Hello again. :cool:

I was wondering if there is some kind of change event or Me.Dirty property that is activated in Access 97 whenever a change occurs to a field. I know that each field has a change event but this form has about 20 fields on them and don't want to deal with the double typing.

What I want to do is change the value of a "Updated By" field to blank if any field on a form is modified. I have heard in Access 2000 that there is a Me.Dirty event. I guess 97 doesn't have that. Is there another option

Thanks
 
Access 97 absolutely has a .Dirty property, but as in 2000, it's for Forms. The .Dirty property is True when a record on a form has been changed in some way, but the changes have not yet been saved.

Sounds like the event is what you're looking for. I'm not that great with events. I can suggest something and if someone has a better idea, they can post it.

Set the Key Preview property of the Form to "Yes" and place code in the On Key Up event of the Form. Any time a key is released on the keyboard, the event will fire. You can put some code like this in it to change the "Updated By" field to blank if it isn't already blank:

Code:
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
    If Me.Dirty Then
        If Not (Me.txtUpdatedBy = "" Or IsNull(Me.txtUpdatedBy)) Then
            Me.txtUpdatedBy = ""
        End If
    End If
End Sub
 
Aha. I see the confusion here. Sorry, you are correct. Access 2000 has a form-level event called "On Dirty". Access 97 does not have anything similar.
 
Thanks for the help but something really weird is going on here.

I put in the code and tested it. It wasn't working for some reason. So I decided to add a watch on the If statement. I retested it and it works.

So then I took off the watch and tried retesting it and it wasn't working. Here is where it gets weird. I was doing the transaction and it wasn't showing it as working. Then I click on Word for something else I was doing. When I got back to Access, the Updated By field was blanked out. Now I didn't blank out that field myself so I would think the code is doing.

I know that makes no sense but does anyone have a idea what is going on here.

:confused:
 
:confused: I am as confused as you. Hopefully someone can help us out here.
 
The event that you want is the FORM's BeforeUpdate event. It is the last event executed before a record is saved. It is ALWAYS executed when a record has been dirtied, even if you close the db. The only way to circumvent it is a power-off. You can set the UpdatedBy field here and any time a record is added or changed, UpdatedBy will be updated. Just a single line of code.

Me.UpdatedBy = CurrentUser()

If you are not using Access security, replace CurrentUser() with your user's id.
 

Users who are viewing this thread

Back
Top Bottom