Results 1 to 4 of 4
  1. #1
    SierraJuliet's Avatar
    SierraJuliet is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Dec 2017
    Location
    Earth
    Posts
    211

    Date and Time in VBA

    I would like to have date and time field on form populate with the current date and current time in separate fields when an entry is created. The date is Short Date and the time is Long Time format. This is for auditing purposes and has a separate Last Modified field. The following code does not work, any suggestions?

    Code:
    Private Sub Form_BeforeInsert(Cancel As Integer)
        Me![txtDateCreated] = Date
        Me![txtTimeCreated] = Time
    End Sub
    
    
    Private Sub Form_BeforeUpdate(Cancel As Integer)
        Me![txtLastModified] = Now()
    End Sub


  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,820
    Why don't you use textbox DefaultValue property?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    SierraJuliet's Avatar
    SierraJuliet is offline Competent Performer
    Windows 7 64bit Access 2013 64bit
    Join Date
    Dec 2017
    Location
    Earth
    Posts
    211
    Trying to keep everything in VBA for ease of troubleshooting and not having to navigate from table level to form level to VBA level when an issue arises.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,820
    Okay, but I still recommend DefaultValue for this.

    Otherwise use OnCurrent event:

    If Me.NewRecord Then
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 5
    Last Post: 09-16-2018, 04:58 PM
  2. Replies: 6
    Last Post: 04-19-2016, 03:58 PM
  3. Replies: 11
    Last Post: 07-20-2014, 06:22 PM
  4. Subtracting a date/time field from a number to get date/time
    By Lifeseeker1019 in forum Programming
    Replies: 4
    Last Post: 03-28-2014, 12:59 PM
  5. Replies: 1
    Last Post: 03-13-2014, 07:23 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