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

Me.Dirty

Status
Not open for further replies.

nicholsk

Technical User
Feb 15, 2005
2
CA
I am trying to set my form so that as soon as a field on the main form or in the sub-form is changed, the LastModifiedDate is automatically changed to today's date.

The LastModifiedDate has the following:
Date Type = Date/Time
Default Value = Date()
Validation Rule = <= Date()
Validation Text = Last Modified Date cannot be greater than today.


This is the code I have written in the Form_frmClients(Code) window:
Private Sub Form_AfterUpdate()

If Me.Dirty = False Then
[LastModifiedDate] = Date
End If

End Sub

I can tab to different fields, and I think it's when I tab off of the Modified date field that it changes. But now I can't got to another records. A message box appears saying "You can't go to the specified record." This happens when I try to go forward or backward. If I try to close out of the form completely, a message box appears saying "You can't save this records at this time. Microsoft Access may have encountered an error while to save a record. If you close the object now, the data changes may be lost...." If I choose to close the form anyway and then open it up again, the information that I added is still there and has not been lost.

And just as a side note....why is it Me.Dirty = False? I would think it would be True since I am looking for changes.

Thanks!
 
You need to use the forms BeforeUpdate event! You may wish to use Now() rather than Date() to catch the time as well. You do not need to look at the Dirty property for a TimeStamp function. The BeforeUpdate and AfterUpdate events *only* occur when the record has been Dirty and you move off of the record or try and close the form.

HTH RuralGuy (RG for short) acXP winXP Pro
Please respond to this forum so all may benefit
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top