Consulting

Results 1 to 6 of 6

Thread: Current date and time

  1. #1
    VBAX Contributor
    Joined
    Apr 2010
    Posts
    182
    Location

    Current date and time

    Hi anyone,

    I'm trying to automatically enter current data & time to the table tblCustomers when a user enters customer information to the form customers and click the next record button.

    Any hep on this would be kindly appreciated.

    I've attached the database for your reference.

    Thanks in advance.
    Best Regards,
    adamsm

  2. #2
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    In the field's Default Value enter
    =Format(Now(),"hh:mm:ss")
    For the Time and
    and
    =Format(Now(),"mm/dd/yyyy")
    for the date.

  3. #3
    VBAX Contributor
    Joined
    Apr 2010
    Posts
    182
    Location
    Thanks for the help OBP. I do really appreciate your help.
    Best Regards,
    adamsm

  4. #4
    VBAX Contributor
    Joined
    Apr 2010
    Posts
    182
    Location
    I’m sorry to post back again. But there seems to be a problem when I created the Customers list form from the customers query table.

    Meaning, the current time and date also gets written in the row where “New” exists even in the absence of other record columns.

    Also the data rows are sorted by newest to the old.

    But in the customers table the data rows are sorted by oldest to newest.

    How the data rows could be adjusted by old to new in the Customers List form?

    I’ve attached the current version for your reference

    Any help on this would be kindly appreciated.

    Thanks in advance.
    Best Regards,
    adamsm

  5. #5
    Quote Originally Posted by OBP
    In the field's Default Value enter
    =Format(Now(),"hh:mm:ss")
    For the Time and
    and
    =Format(Now(),"mm/dd/yyyy")
    for the date.
    If the data type for the fields is Date/Time, then you should NOT use the Format() which returns a string, not a Date/Time data type.

    What you are suggestion does is cause a lot of extra overhead and is not very effient.

    Example:
    Using the Default of =Format(Now(),"hh:mm:ss") to set the Time into a Date/time data type does this:

    1) Now() returns the date and time in the date/time data type
    2) Format() strips the date and formats the time as a string
    3) = Nowe access must convert the string from the format back to a date/time data type.

    What you should use is just: Time() without the = sign. This returns just the Time in the correct data type.

    The same will hold true for the Date: Just use: Date()


    @ adamsm: It is actually better/more efficient to store the date and time in a single field. Then you would use the Format() as OBP is suggesting when you want to display the Date or Time separately.
    Boyd Trimmell aka HiTechCoach
    Microsoft Access MVP -2010-2015

    Programming: Nine different ways to do it right, a thousand ways to do it wrong.
    Binary--it's as easy as 1-10-11

  6. #6
    Quote Originally Posted by adamsm
    I’m sorry to post back again. But there seems to be a problem when I created the Customers list form from the customers query table.

    Meaning, the current time and date also gets written in the row where “New” exists even in the absence of other record columns.

    Also the data rows are sorted by newest to the old.

    But in the customers table the data rows are sorted by oldest to newest.

    How the data rows could be adjusted by old to new in the Customers List form?

    I’ve attached the current version for your reference

    Any help on this would be kindly appreciated.

    Thanks in advance.
    You need to sort descending on the date and time fields. Note: If you use one field for both the date and time, you would only need to sort by one field.

    Note: I also change the default values in the table.

    See attached.
    Boyd Trimmell aka HiTechCoach
    Microsoft Access MVP -2010-2015

    Programming: Nine different ways to do it right, a thousand ways to do it wrong.
    Binary--it's as easy as 1-10-11

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •