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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AccessBeetle
    New Member
    • Jul 2009
    • 111

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

    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.
    Code:
    Private Sub Comments_AfterUpdate()
    Me.Text42.Value = Format(Now(), "Medium Time")
    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!!
  • TheSmileyCoder
    Recognized Expert Moderator Top Contributor
    • Dec 2009
    • 2322

    #2
    Quite simple.
    Code:
    Private Sub Comments_AfterUpdate() 
      If Me.NewRecord then
        Me.Text42.Value = Format(Now(), "Medium Time") 
      End If
    End Sub

    Comment

    • missinglinq
      Recognized Expert Specialist
      • Nov 2006
      • 3533

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

      Comment

      • TheSmileyCoder
        Recognized Expert Moderator Top Contributor
        • Dec 2009
        • 2322

        #4
        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.

        Comment

        • AccessBeetle
          New Member
          • Jul 2009
          • 111

          #5
          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)
          Code:
          Private Sub Form_BeforeUpdate(Cancel As Integer)
          If Me.NewRecord Then
          Me.txtTimeStamp.Value = Format(Now(), "Medium Time")
          End If
          End Sub
          It worked perfectly. Thanks.

          Comment

          • missinglinq
            Recognized Expert Specialist
            • Nov 2006
            • 3533

            #6
            Glad we could help!

            Linq ;0)>

            Comment

            Working...