473,407 Members | 2,315 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

How to Time Stamp entries?

I need to associate a Creation Date and a Modified Date with each entry in
my database. How to do this?

Here's what I've tried:

1) Use a separate table (tblUpdate) with Created, Modified, and Entry_ID
fields that has a One-To-Many relationship with the main table (tblMain -
the "one" side of the relationship) which holds all the names, addresses,
etc.

2) Have an update query run every time an entry is added, or modified:

UPDATE tblUpdate SET tblUpdate.Modified = Now()
WHERE (("Entry_ID"=[Forms]![frmMain]![frmCn].[Form]![Entry_ID]));

But how do I get every Entry_ID from tblMain into tblUpdate? Do I have to
write it every time? What if the Entry_ID does not yet exist? Does that
mean I also need an Append Query for new entries in tblMain?

If possible, I want to avoid having any form associated with tblUpdate
because I'll be writing to it from several different forms and subforms
within the database. Does this mean I'll be updating it exclusively with
SQL statements rather than Jet? Is there a performance penalty for doing
this?

Has anyone done this before? Is there a better way?

Thanks in advance!!
Nov 12 '05 #1
7 15522
I don't believe you have any choices here.
You have to run the code in every place where you allow updates to take
place.
But I can see no point at all in making it so difficult by putting the
fields into a separate table.

If the fields were in the same table as the data then
the creation date could be entered automatically with a default value of
Now. You would just need a me.lastmodified = Now statement in the form's
beforeupdate event wherever you allow changes.

Regards

Peter Russell

deko previously wrote:
I need to associate a Creation Date and a Modified Date with each entry
in
my database. How to do this?

Here's what I've tried:

1) Use a separate table (tblUpdate) with Created, Modified, and
Entry_ID
fields that has a One-To-Many relationship with the main table (tblMain
-
the "one" side of the relationship) which holds all the names,
addresses,
etc.

2) Have an update query run every time an entry is added, or modified:

UPDATE tblUpdate SET tblUpdate.Modified = Now()
WHERE (("Entry_ID"=[Forms]![frmMain]![frmCn].[Form]![Entry_ID]));

But how do I get every Entry_ID from tblMain into tblUpdate? Do I have
to
write it every time? What if the Entry_ID does not yet exist? Does
that
mean I also need an Append Query for new entries in tblMain?

If possible, I want to avoid having any form associated with tblUpdate
because I'll be writing to it from several different forms and subforms
within the database. Does this mean I'll be updating it exclusively
with
SQL statements rather than Jet? Is there a performance penalty for
doing
this?

Has anyone done this before? Is there a better way?

Thanks in advance!!


Nov 12 '05 #2
hmmm... sounds like a plan... BUT:

1) sometimes I'm in a subform, or popup form, or other form that holds data
associated with the entry in question. This other form does NOT use tblMain
as a RecordSource. So, when a change is made, the Modification Date needs
to be written... the only way I know how to do this is:

DoCmd.RunSql ("UPDATE tblMain SET ModificationDate = Now() WHERE
Entry_ID = " & Me!Entry_ID)

After I do this, there are conflicts when I go back to frmMain (The form
that DOES use tblMain as a RecordSource) and try to make additions/edits
AFTER writing the Modification Date to the underlying table.

Do I need to requery the main form every time the ModificationDate is
changed? If so, This means I have to also move frmMain back to the record
it was on before the write (or else the user has to manually go back).
Here's how I do it in code:

Dim rst as DAO.recordset
Set rst = Me.RecordsetClone
rst.FindFirst ("Entry_ID=" & lngEid)
Me.Bookmark = rst.Bookmark
rst.Close
Set rst = Nothing

(does this code look okay, by the way?)

2) ALSO -- if frmMain is Dirty, then does it have to be requeried BEFORE the
Modification Date is written? I've gotten errors when this is the case...

3) ALSO -- what about the size of tblMain? Will all these dates cause it to
grow too fast? Wouldn't it be better to have all the dates in a separate
table -- AND would this avoid the conflicts and requery/move-back issues
mentioned above??

Thanks again for the reply and advice!
"Peter Russell" <ru***@127.0.0.1> wrote in message
news:me***********************@russellscott.btinte rnet.com...
I don't believe you have any choices here.
You have to run the code in every place where you allow updates to take
place.
But I can see no point at all in making it so difficult by putting the
fields into a separate table.

If the fields were in the same table as the data then
the creation date could be entered automatically with a default value of
Now. You would just need a me.lastmodified = Now statement in the form's
beforeupdate event wherever you allow changes.

Regards

Peter Russell

deko previously wrote:
I need to associate a Creation Date and a Modified Date with each entry
in
my database. How to do this?

Here's what I've tried:

1) Use a separate table (tblUpdate) with Created, Modified, and
Entry_ID
fields that has a One-To-Many relationship with the main table (tblMain
-
the "one" side of the relationship) which holds all the names,
addresses,
etc.

2) Have an update query run every time an entry is added, or modified:

UPDATE tblUpdate SET tblUpdate.Modified = Now()
WHERE (("Entry_ID"=[Forms]![frmMain]![frmCn].[Form]![Entry_ID]));

But how do I get every Entry_ID from tblMain into tblUpdate? Do I have
to
write it every time? What if the Entry_ID does not yet exist? Does
that
mean I also need an Append Query for new entries in tblMain?

If possible, I want to avoid having any form associated with tblUpdate
because I'll be writing to it from several different forms and subforms
within the database. Does this mean I'll be updating it exclusively
with
SQL statements rather than Jet? Is there a performance penalty for
doing
this?

Has anyone done this before? Is there a better way?

Thanks in advance!!

Nov 12 '05 #3
"deko" <dj****@hotmail.com> wrote in message news:<DA*****************@newssvr27.news.prodigy.c om>...
I need to associate a Creation Date and a Modified Date with each entry in
my database. How to do this?


RTFM.
Creation Date: Default Value (table level) = Date() or Now()
Modified Date: Set in the BeforeUpdate event of a form... can't be
done at table level.
Nov 12 '05 #4
deko previously wrote:
hmmm... sounds like a plan... BUT:

1) sometimes I'm in a subform, or popup form, or other form that holds
data
associated with the entry in question. This other form does NOT use
tblMain
as a RecordSource. So, when a change is made, the Modification Date
needs
to be written... the only way I know how to do this is:

DoCmd.RunSql ("UPDATE tblMain SET ModificationDate = Now() WHERE
Entry_ID = " & Me!Entry_ID)


You've lost me.

How can you be changing (through the UI) a field in tblMain if the form is
not based on that table? And if you're not changing a record in tblMain
why would you want to update its modification date?

Regards

Peter Russell

Nov 12 '05 #5
good question.

I have a table (tblTxJournal) which holds transactions for each Entry. Each
Entry's Entry_ID is in tblTxJournal (I think this is called a Foreign Key?)
with a One-To-Many relationship with tblMain (tblMain is the "one" side).
The UI is a tabbed interface, so when the user goes to enter/add a
transaction on frmTx, frmMain remains open, and the Entry_ID is pulled from
frmMain when editing/saving a transaction:

Private Sub cmdRecord_Click()
lngEid = Forms!frmMain!Entry_ID 'get Entry_ID
Me!Entry_ID = lngEid 'put it in txtBox bound to Entry_ID in tblTx
DoCmd.RunCommand acCmdSaveRecord
End Sub

Whenever an Entry's transaction is modified/added, the DateModified field
(in tblMain) needs to be updated. One way to do this would be adding this
line to the above sub on frmTx:

Forms!frmMain!DateModified = Now

This would set the current date on frmMain (and the underlying RecordSource
tblMain) -- without the user actually being in that form.

But problems arise when the user goes back to frmMain and makes changes --
or goes to frmTx while frmMain is Dirty. This is why I'm thinking a
separate table might be best -- simply to avoid problems.

UPDATE tblUtility SET Modified = Now()
WHERE Entry_ID=Forms!Tx!Entity_ID;

What do you think?
"Peter Russell" <ru***@127.0.0.1> wrote in message
news:me***********************@russellscott.btinte rnet.com...
deko previously wrote:
hmmm... sounds like a plan... BUT:

1) sometimes I'm in a subform, or popup form, or other form that holds
data
associated with the entry in question. This other form does NOT use
tblMain
as a RecordSource. So, when a change is made, the Modification Date
needs
to be written... the only way I know how to do this is:

DoCmd.RunSql ("UPDATE tblMain SET ModificationDate = Now() WHERE
Entry_ID = " & Me!Entry_ID)


You've lost me.

How can you be changing (through the UI) a field in tblMain if the form is
not based on that table? And if you're not changing a record in tblMain
why would you want to update its modification date?

Regards

Peter Russell

Nov 12 '05 #6
I don't know if I'm getting somewhere near it yet.

My understanding now is that you have a main table and a transactions
table.

The transaction are all timestamped.

What you want is the form for the main table to display the latest
timestamp on any related transaction.

If this is the case then don't keep the timestamp data on the main table
at all. Just look it up using DMax. You can requery the field after each
transaction.

Am I missing the point here?

Regards

Peter Russell


deko previously wrote:
good question.

I have a table (tblTxJournal) which holds transactions for each Entry.
Each
Entry's Entry_ID is in tblTxJournal (I think this is called a Foreign
Key?)
with a One-To-Many relationship with tblMain (tblMain is the "one"
side).
The UI is a tabbed interface, so when the user goes to enter/add a
transaction on frmTx, frmMain remains open, and the Entry_ID is pulled
from
frmMain when editing/saving a transaction:

Private Sub cmdRecord_Click()
lngEid = Forms!frmMain!Entry_ID 'get Entry_ID
Me!Entry_ID = lngEid 'put it in txtBox bound to Entry_ID in tblTx
DoCmd.RunCommand acCmdSaveRecord
End Sub

Whenever an Entry's transaction is modified/added, the DateModified
field
(in tblMain) needs to be updated. One way to do this would be adding
this
line to the above sub on frmTx:

Forms!frmMain!DateModified = Now

This would set the current date on frmMain (and the underlying
RecordSource
tblMain) -- without the user actually being in that form.

But problems arise when the user goes back to frmMain and makes changes
-- or goes to frmTx while frmMain is Dirty. This is why I'm thinking a
separate table might be best -- simply to avoid problems.

UPDATE tblUtility SET Modified = Now()
WHERE Entry_ID=Forms!Tx!Entity_ID;

What do you think?
"Peter Russell" <ru***@127.0.0.1> wrote in message
news:me***********************@russellscott.btinte rnet.com...
deko previously wrote:
hmmm... sounds like a plan... BUT:

1) sometimes I'm in a subform, or popup form, or other form that
holds
data
associated with the entry in question. This other form does NOT use
tblMain
as a RecordSource. So, when a change is made, the Modification Date
needs
to be written... the only way I know how to do this is:

DoCmd.RunSql ("UPDATE tblMain SET ModificationDate = Now() WHERE
Entry_ID = " & Me!Entry_ID)


You've lost me.

How can you be changing (through the UI) a field in tblMain if the
form is
not based on that table? And if you're not changing a record in
tblMain
why would you want to update its modification date?

Regards

Peter Russell



Nov 12 '05 #7
well, I've prototyping the separate table solution and it seems to be
working.

what I have is an append query that inserts creation date in tblUtility for
new entries, and an Update query that writes modification dates to that same
table. The key was to know where to fire off the Update query -- your
suggestion of on BeforeUpdate is a winner.

I have many tables that are all linked on Entry_ID with many forms that use
these tables as recordsources. The solution I've designed will allow me to
update the modification date for a particular Entry when related data for
that Entry -- in any of the related tables -- is changed. And because
tblUtility is not used as a recordsource for any form, I don't have to worry
about write conflicts and other problems that I've experienced when I tried
to use tblMain for this.

thanks for the time on DMax... may come in handy elsewhere

appreciate your comments very much!!
"Peter Russell" <ru***@127.0.0.1> wrote in message
news:me***********************@russellscott.btinte rnet.com...
I don't know if I'm getting somewhere near it yet.

My understanding now is that you have a main table and a transactions
table.

The transaction are all timestamped.

What you want is the form for the main table to display the latest
timestamp on any related transaction.

If this is the case then don't keep the timestamp data on the main table
at all. Just look it up using DMax. You can requery the field after each
transaction.

Am I missing the point here?

Regards

Peter Russell


deko previously wrote:
good question.

I have a table (tblTxJournal) which holds transactions for each Entry.
Each
Entry's Entry_ID is in tblTxJournal (I think this is called a Foreign
Key?)
with a One-To-Many relationship with tblMain (tblMain is the "one"
side).
The UI is a tabbed interface, so when the user goes to enter/add a
transaction on frmTx, frmMain remains open, and the Entry_ID is pulled
from
frmMain when editing/saving a transaction:

Private Sub cmdRecord_Click()
lngEid = Forms!frmMain!Entry_ID 'get Entry_ID
Me!Entry_ID = lngEid 'put it in txtBox bound to Entry_ID in tblTx
DoCmd.RunCommand acCmdSaveRecord
End Sub

Whenever an Entry's transaction is modified/added, the DateModified
field
(in tblMain) needs to be updated. One way to do this would be adding
this
line to the above sub on frmTx:

Forms!frmMain!DateModified = Now

This would set the current date on frmMain (and the underlying
RecordSource
tblMain) -- without the user actually being in that form.

But problems arise when the user goes back to frmMain and makes changes
-- or goes to frmTx while frmMain is Dirty. This is why I'm thinking a
separate table might be best -- simply to avoid problems.

UPDATE tblUtility SET Modified = Now()
WHERE Entry_ID=Forms!Tx!Entity_ID;

What do you think?
"Peter Russell" <ru***@127.0.0.1> wrote in message
news:me***********************@russellscott.btinte rnet.com...
deko previously wrote:

> hmmm... sounds like a plan... BUT:
>
> 1) sometimes I'm in a subform, or popup form, or other form that
> holds
> data
> associated with the entry in question. This other form does NOT use
> tblMain
> as a RecordSource. So, when a change is made, the Modification Date
> needs
> to be written... the only way I know how to do this is:
>
> DoCmd.RunSql ("UPDATE tblMain SET ModificationDate = Now() WHERE
> Entry_ID = " & Me!Entry_ID)

You've lost me.

How can you be changing (through the UI) a field in tblMain if the
form is
not based on that table? And if you're not changing a record in
tblMain
why would you want to update its modification date?

Regards

Peter Russell


Nov 12 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Marcus | last post by:
I am having some problems with trying to perform calculations on time fields. Say I have a start time and an end time, 1:00:00 and 2:30:00 (on a 24 hour scale, not 12). I want to find the...
10
by: Yang Li Ke | last post by:
Hi guys, Im about to build a script which will log visitor time spent on my website. I got a few ideas about this, maybe checking visitors ip and storing that info in db with time in and then...
1
by: Bill | last post by:
I have a shopping cart that will get full from time to time because customers click out of the site before they confirm their purchase, therefore leaving a full cart behind. I'd like to have a...
7
by: Don | last post by:
Hi all, With regards to the following, how do I append the datetimestamp to the filenames in the form? The files are processed using the PHP script that follows below. Thanks in advance,...
18
by: Sven | last post by:
Hi, I found a strange behaviour when using the time() function from time.h. Sometimes when it is called, it does not show the correct time in seconds, but an initial value. This time seem to be...
3
by: phried1 | last post by:
I have created a form and inserted the following tables: Date Entered Time Entered Date Modified Time Modified Essentially how and where can I have these dates and times recorded so when the...
1
MitchR
by: MitchR | last post by:
I have created a text box and scripted it to receive a line of text and current date upon completion of a scripted event. My question is this. I need to script this text box and date stamp to...
4
by: SilentThunderer | last post by:
Hey folks, Let me start out by letting you know what I'm working with. I'm building an application in VB 2005 that is basically a userform that employees can use to "Clock in". The form...
2
by: Shane | last post by:
I'm writing a program for renaming my picture files, and I want to use the picture time stamp as a prefix to the file names. I can get the time stamp, but it is extraordinarily slow! I have about...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.