When has data on a form changed

TimTDP

Registered User.
Local time
Today, 18:08
Joined
Oct 24, 2008
Messages
213
I need to know when:
* a new record has been created
* data on a record has been changed

Does the On Dirty event capture this, or can I just use the forms On Change event?
 
if me.dirty = true then it means that some data on the form has been changed but the underlying record has not been updated

An event On Dirty does not exist - use before and after update events for the form or change event for controls

inserting a new record will trigger the before and after insert events on the form

This link may help explain more

http://www.blueclaw-db.com/access_event_programming/
 
Actually an OnDirty event does, in fact, exist for Forms, but the standard way to do something, such as toTimeStamp an Edit of an Existing Record or TimeStamp the creation of a New Record is, as CJ said, to use the Form_BeforeUpdate event. Here's an example of this sort of thing:
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
 If Me.NewRecord Then
  Me.CreationDate = Date
 Else
  Me.EditDate = Date
 End If
End Sub
You can use the same type of code in the Form_Current event if you need to know, immediately, whether you're on an Existing Record or starting a New Record.

The Form_BeforeUpdate event only pops if new data is added to a Form or existing data is changed. If, for instance, you start a New Record, then change you mind, and dump it, the Form_BeforeUpdate event will not fire. More importantly, if you edit data in an Existing Record, change your mind and return the data to its previous state, the event won't fire, so anything that depends on an edit being done will not be executed unless an edit is actually done, not if you only think about doing an edit then change your mind!

The OnChange event of a Control, especially a Textbox or Combobox, is only rarely used, because that event fires each and every time a character is entered into the Control, not when you've completed entering data into it, which, depending on what you're doing, can lead to unexpected results.

Linq ;0)>
 

Users who are viewing this thread

Back
Top Bottom