If sheet is updated fill in date field? (1 Viewer)

sullivan

Registered User.
Local time
Today, 12:51
Joined
Apr 24, 2001
Messages
48
I'm trying to have an "Edited Date" field automatically filled in whenever any field, per record, on a form is edited. This sounds like a simple enough task to program, but I am confused about what commands to use when entering code. I thought I could enter an expression in the Event Field "AfterUpdate" of the Form's property sheet, but I'm having trouble coming up with the correct series of code. I thought something like If Me.Updated (but that's not a command) Then Edited Date = Now()

Am I way off base here? Is something like this possible, or can it only be used in a specific field? Obviously I'm not very well versed in programming.
Thanks in advance.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 07:51
Joined
Feb 19, 2002
Messages
43,346
In the BeforeUpdate event of the form:

Me.EditedDate = Now()

The BeforeUpdate event is the last event fired prior to a record's actually being saved. NEVER use the Form's AfterUpdate event to modify form data. It will put Access into a loop and cause strange problems. The AfterUpdate event is fired immediately AFTER Access saves the data. If you dirty the form by changing the value of a bound field, you will force the BeforeUpdate event to fire again to save the "new" changes. Following that, the AfterUpdate event will fire, dirtying the record all over again. Ergo - loop.
 

sullivan

Registered User.
Local time
Today, 12:51
Joined
Apr 24, 2001
Messages
48
Pat, I tried putting Me.DateEdited=() into the BeforeUpdate event of the form, but I get an error saying that the DB can't find the macro Me. Do I need to enter this expression as a macro to make it work?
Thanks,
Jennie
 

ColinEssex

Old registered user
Local time
Today, 12:51
Joined
Feb 22, 2002
Messages
9,116
Hi Jennie

Select [Event Procedure] on the Before Update line of the form properties.

Then click the little button with 3 dots on it ...

then in the code window type

Me.YourFieldNameHere = Now()

If you just type it into the line on the properties bit, it thinks its a macro, so you need to select the Event Procedure bit then go "behind" the form to enter the code. The "Me" refers to the form.

Hope this helps

Col


:cool:
 

sullivan

Registered User.
Local time
Today, 12:51
Joined
Apr 24, 2001
Messages
48
I have another problem and I'm wondering if the code in the form is causing it. I want to use the date that is entered automatically by the code, as criteria in a parameter query. In the parameter query I entered: Between [Enter Beginning Date] and [Enter Ending Date]

The problem is it is only pulling up one record for each date. The table shows that the code is working correctly on the form, there are several dates listed in the table. However, only one of these records is being pulled. I've used parameter queries before and have never run into this problem. Does anyone have a suggestion? Is this maybe a result of the code?
 

Users who are viewing this thread

Top Bottom