By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,665 Members | 2,646 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,665 IT Pros & Developers. It's quick & easy.

Time changes in a textbox when I edit the previously added record.

100+
P: 111
I have asked this question before and I got the answer but now there is an extension in User's requirement.
Here is the issue.
On a form there is a timestamp field, which saves the time when the record is completely entered.
I have this code written because user wants to refresh the time when he is done with entering record.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Comments_AfterUpdate()
  2. Me.Text42.Value = Format(Now(), "Medium Time")
  3. End Sub
Comments is the another textbox on the same form.
Now if user logs in next day and want to edit a record that is entered today, the time in the timestamp field should not change.
In my case due to the code written above it refreshes the timestamp field with current time.
How can I stop refreshing the timestamp field when user is editing?
The time can not change if they go back and edit a record. It has to remain as it was when the record was added...

Please help!!
Mar 4 '10 #1

✓ answered by missinglinq

I'm confused. In your previous thread you were told and said you understood that the code needed to be in the Form_BeforeUpdate event, and now you appear to have it back in the Comments_AfterUpdate event. At any rate, this will keep it from being executed unless you're entering a new record:
Expand|Select|Wrap|Line Numbers
  1. If Me.NewRecord Then
  2.   Me.Text42.Value = Format(Now(), "Medium Time")
  3. End If
Linq ;0)>

Share this Question
Share on Google+
5 Replies


TheSmileyCoder
Expert Mod 100+
P: 2,321
Quite simple.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Comments_AfterUpdate() 
  2.   If Me.NewRecord then
  3.     Me.Text42.Value = Format(Now(), "Medium Time") 
  4.   End If
  5. End Sub
Mar 4 '10 #2

missinglinq
Expert 2.5K+
P: 3,532
I'm confused. In your previous thread you were told and said you understood that the code needed to be in the Form_BeforeUpdate event, and now you appear to have it back in the Comments_AfterUpdate event. At any rate, this will keep it from being executed unless you're entering a new record:
Expand|Select|Wrap|Line Numbers
  1. If Me.NewRecord Then
  2.   Me.Text42.Value = Format(Now(), "Medium Time")
  3. End If
Linq ;0)>
Mar 4 '10 #3

TheSmileyCoder
Expert Mod 100+
P: 2,321
While we are at it, you will save ALOT of trouble if you as a minimum rename all controls used in code. Text42 tells you nothing about what your setting.

Could call it something like:
tb_TimeStamp
the tb being short for TextBox.
Mar 4 '10 #4

100+
P: 111
Sorry sir,
I was reading the previous thread to look for any clue to solve this question. By mistake I copied the things from there and pasted here thinking that I have copied it from my coding. Really sorry. This is what happens when you have to deal with a user who changes requirements three times a day!!
Anyways, here is the correct code (I make sure this time I am not pasting anything by mistake)
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2. If Me.NewRecord Then
  3. Me.txtTimeStamp.Value = Format(Now(), "Medium Time")
  4. End If
  5. End Sub
It worked perfectly. Thanks.
Mar 4 '10 #5

missinglinq
Expert 2.5K+
P: 3,532
Glad we could help!

Linq ;0)>
Mar 4 '10 #6

Post your reply

Sign in to post your reply or Sign up for a free account.