A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Database Design
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

date/time last updated field



 
 
Thread Tools Display Modes
  #1  
Old January 21st, 2008, 09:41 AM posted to microsoft.public.access.tablesdbdesign
KumbiaKid
external usenet poster
 
Posts: 21
Default date/time last updated field

I'd like to have a field in a table that records the date/time that the
record was last updated. I'd like this field to be automatically updated
whenever any other field in the table is changed (or a new record is created
-- that part is easy). Any way I can do that in the table? I'd prefer to do
it there so I don't have to repeat code for different forms or queries that
allow updates to the table. I'm using Access 2000, but may be able to use
Access 2003 and I'll soon be updating to Access 2007, so if there's a
solution that works with all of these versions, that would be ideal.
  #2  
Old January 21st, 2008, 09:54 AM posted to microsoft.public.access.tablesdbdesign
Allen Browne
external usenet poster
 
Posts: 11,706
Default date/time last updated field

No. Access lacks triggers, so you cannot do that at the table level.

You can do it at the form level. Use the BeforeUpdate event procedure of the
form.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"KumbiaKid" wrote in message
...
I'd like to have a field in a table that records the date/time that the
record was last updated. I'd like this field to be automatically updated
whenever any other field in the table is changed (or a new record is
created
-- that part is easy). Any way I can do that in the table? I'd prefer to
do
it there so I don't have to repeat code for different forms or queries
that
allow updates to the table. I'm using Access 2000, but may be able to use
Access 2003 and I'll soon be updating to Access 2007, so if there's a
solution that works with all of these versions, that would be ideal.


  #3  
Old January 21st, 2008, 03:20 PM posted to microsoft.public.access.tablesdbdesign
Jamie Collins
external usenet poster
 
Posts: 1,705
Default date/time last updated field

On Jan 21, 9:54 am, "Allen Browne" wrote:
I'd like to have a field in a table that records the date/time that the
record was last updated. I'd like this field to be automatically updated
whenever any other field in the table is changed (or a new record is
created

can do that in the table? I'd prefer to


No. Access lacks triggers, so you cannot do that at the table level.


Did you mean to say, "Jet lacks triggers..."?

At the very least the OP should put a validation rule in the table to
ensure the 'timestamp' is maintained e.g. column-level rule

= NOW()

Jamie.

--

  #4  
Old January 21st, 2008, 04:53 PM posted to microsoft.public.access.tablesdbdesign
TedMi
external usenet poster
 
Posts: 507
Default date/time last updated field

As Allen says, this must be done at the form level, but there is very little
code to duplicate across multiple forms. Place a control (e.g. textbox) on
each form, make its data source the timestamp field of your table. You could
make this hidden if users are not to see the timestamp - if visible, it
should be locked. The BeforeUpdate event is one line of code:
txtboxTimeStamp=Now()

For queries that update this table, insert TimeStamp=Now() into the SET
clause of each query.
--
TedMi

  #5  
Old January 21st, 2008, 05:08 PM posted to microsoft.public.access.tablesdbdesign
Klatuu
external usenet poster
 
Posts: 7,074
Default date/time last updated field

You are accurate, but a bit nit picky. I am sure Allen said Access to avoid
confusing the OP. You would be surprised at how many users do not understand
the distinction between Access and Jet.

Should we educate? Sure, but it takes baby steps. As in teaching music, you
don't introduce a E# min Add 9 to someone who barely understands a C major
code.
Yes, I said E#. Yes it is really F, but it is taught as a reading exercise.
--
Dave Hargis, Microsoft Access MVP


"Jamie Collins" wrote:

On Jan 21, 9:54 am, "Allen Browne" wrote:
I'd like to have a field in a table that records the date/time that the
record was last updated. I'd like this field to be automatically updated
whenever any other field in the table is changed (or a new record is
created

can do that in the table? I'd prefer to


No. Access lacks triggers, so you cannot do that at the table level.


Did you mean to say, "Jet lacks triggers..."?

At the very least the OP should put a validation rule in the table to
ensure the 'timestamp' is maintained e.g. column-level rule

= NOW()

Jamie.

--


  #6  
Old January 21st, 2008, 10:13 PM posted to microsoft.public.access.tablesdbdesign
Jamie Collins
external usenet poster
 
Posts: 1,705
Default date/time last updated field

On Jan 21, 5:08 pm, Klatuu wrote:
No. Access lacks triggers, so you cannot do that at the table level.


Did you mean to say, "Jet lacks triggers..."?


You are accurate, but a bit nit picky. I am sure Allen said Access to avoid
confusing the OP.


It's more about being specific (do you really think the OP would have
been confused by the use of the term 'Jet'?)

I considered my point worthy because in a sense Access has triggers
(i.e. Form events) whereas Jet does not.

Jamie.

--

  #7  
Old January 23rd, 2008, 12:34 AM posted to microsoft.public.access.tablesdbdesign
KumbiaKid
external usenet poster
 
Posts: 21
Default date/time last updated field

Thanks all. Although I'm an old timer at database design, I'm very green at
this sort of coding and at application development in Access/VB etc. I've
created an event procedure for the BeforeUpdate event with the following code
(the name of the field is DateLastModified):

Private Sub Form_BeforeUpdate(Cancel As Integer)
DateLastModified = Now()
End Sub

Visual Basic started with "Option Compare Database" above the code section
-- I don't know what that's about, but presume it should be there.

This makes no change in the DateLastModified field when I make a change in
another field. What am I missing?

"tedmi" wrote:

As Allen says, this must be done at the form level, but there is very little
code to duplicate across multiple forms. Place a control (e.g. textbox) on
each form, make its data source the timestamp field of your table. You could
make this hidden if users are not to see the timestamp - if visible, it
should be locked. The BeforeUpdate event is one line of code:
txtboxTimeStamp=Now()

For queries that update this table, insert TimeStamp=Now() into the SET
clause of each query.
--
TedMi

  #8  
Old January 23rd, 2008, 12:36 AM posted to microsoft.public.access.tablesdbdesign
TedMi
external usenet poster
 
Posts: 507
Default date/time last updated field

LOVE your musical analogy! Wonder how many readers here understand enharmonics?
--
TedMi

  #9  
Old January 23rd, 2008, 12:39 AM posted to microsoft.public.access.tablesdbdesign
KumbiaKid
external usenet poster
 
Posts: 21
Default date/time last updated field

Thanks all. Although I'm well experienced in database design, I'm really a
newbie at application development using Access/VB, etc. I've tried to code an
Event Procedure in a form using TedMi's suggestion. The textbox control is
already a part of the form. The name of the field is DateLastModified and
I've put the following code in an Event Procedure attached to the Before
Update Event:

Private Sub Form_BeforeUpdate(Cancel As Integer)
DateLastModified = Now()
End Sub

There's a line above the code section in the VB window that says "Option
Compare Database" which I presume should be there. When I make a change in
another field in the form, no errors are generated but the DateLastModified
field is not updated. What am I missing?

"tedmi" wrote:

As Allen says, this must be done at the form level, but there is very little
code to duplicate across multiple forms. Place a control (e.g. textbox) on
each form, make its data source the timestamp field of your table. You could
make this hidden if users are not to see the timestamp - if visible, it
should be locked. The BeforeUpdate event is one line of code:
txtboxTimeStamp=Now()

For queries that update this table, insert TimeStamp=Now() into the SET
clause of each query.
--
TedMi

  #10  
Old January 23rd, 2008, 12:42 AM posted to microsoft.public.access.tablesdbdesign
KumbiaKid
external usenet poster
 
Posts: 21
Default date/time last updated field

Thanks all. My reply posts seem to not be making it to the discussion, so I
hope this one does. I guess I was in the wrong group (should have been in
Forms Coding where I found the full solution).

"tedmi" wrote:

As Allen says, this must be done at the form level, but there is very little
code to duplicate across multiple forms. Place a control (e.g. textbox) on
each form, make its data source the timestamp field of your table. You could
make this hidden if users are not to see the timestamp - if visible, it
should be locked. The BeforeUpdate event is one line of code:
txtboxTimeStamp=Now()

For queries that update this table, insert TimeStamp=Now() into the SET
clause of each query.
--
TedMi

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 08:49 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.