Results 1 to 7 of 7
  1. #1
    Detectiveclem is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Jul 2018
    Posts
    8

    Question Date Created and Date last modified

    Can anyone assist.



    I have a Form which has four fields which are causing me some issue, one called 'DateModified', one called'TimeModified' one called 'DateCreated' and finally one called 'TimeCreated'.

    I have managed to auto populate all four fields with the date and time, however when I return to the record in the Form and make any changes, the DateCreated & TimeCreated fields change and mirror the new DateModifiied and TimeModified fields.

    Whilst I want the Modified fields to update, I don't want the create date and time to change. These Create fields should always show the original date/time when the record was first created.

    Any help will be greatly appreciated.

    Thanks

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Instead of separate Date and Time fields, I recommend you use the Now() function which includes date and time.
    For example:
    ?Now()
    29-Aug-18 9:06:48 AM


    I don't think you would want these controls ("fields") bound to the underlying table since any change will update your table field values.

    Please tell us more about what and why exactly are you recording these dates and times.
    It would seem that once the Created info is recorded, you would have code/logic to prevent it from being changed.
    Good luck with your project.

  3. #3
    Detectiveclem is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Jul 2018
    Posts
    8
    Thank you orange, I did consider using the now function, but for my purpose the seperate fields look better.

    The reason I want both the 'Create' and 'Modified' Fields, is because I need to visably show when a new record was created and also when it was last updated. I am not using the dates/times for any other reason.


    As a newbie to Access are you able to lead me through the code/logic I require to prevent to 'Create' fields from changing after the record is first created?

    Thank you.

  4. #4
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    You haven't said much about the code updating the fields, but consider including the .newrecord property for the form.
    Code:
    If Me.Newrecord then 
        'update created fields
        'update modified fields
    else
        'update modified fields
    end if

  5. #5
    Detectiveclem is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Jul 2018
    Posts
    8

    Thank you

    Hi Davegri,

    Thank you, I will try this, do I use this code in the Form or in the fields?

    Cheers

  6. #6
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    I will try this, do I use this code in the Form or in the fields?
    As I said, I don't know how you are set up to add/edit your tables, but this code would be included in the code that creates the new records.
    I don't have enough information to be more specific.

  7. #7
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    If you set the Default values for the created date / times as Now(), simply don't ever update them.
    Lock them down so they can't be edited. In the BeforeUpdate event of the form set the Date / Time Modified to now() before saving the record. Something like

    Code:
    If Me.Dirty Then
       Me.DateModified = Now()
       Me.Dirty = False
    End If
    As others have said you only need one field for each of these.
    If you need the displayed separately just duplicate the field and set the display format to only display the Time value / date value accordingly, and lock them all from direct editing.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 15
    Last Post: 12-07-2014, 06:22 AM
  2. Target Date Based on Created Date
    By mwong1782 in forum Access
    Replies: 1
    Last Post: 12-17-2013, 05:51 PM
  3. modified Date & Modified BY
    By bronson_mech in forum Queries
    Replies: 1
    Last Post: 12-06-2013, 10:45 AM
  4. Replies: 4
    Last Post: 03-06-2013, 02:32 PM
  5. Replies: 5
    Last Post: 12-18-2012, 02:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums