Results 1 to 9 of 9
  1. #1
    Inchman is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Oct 2014
    Location
    NJ
    Posts
    2

    Getting Access to fill in a ‘date created’ field when a record is pasted in a DB

    Hello,

    I have a daily operation that requires users to cut data from excel spreadsheets and paste it into an Access database. The problem is that I need Access to populate a ‘Date Created’ field in the database, but it doesn’t seem to do this when a record is pasted into the database. (Note, it works fine for manually created records in Access using the Now() function.)

    How do I get Access to fill in a ‘date created’ field when a record is pasted?

    I’ve searched the web (and this site) for an answer, but the results are always bogged down with simple answers about creating new records manually.)

    Thanks

  2. #2
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Try using the AfterUpdateEvent.
    Me.SomeField = Date
    HTH

  3. #3
    Inchman is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Oct 2014
    Location
    NJ
    Posts
    2
    Thank you so much for the quick reply!
    I've tried putting this in the form, but it doesn't work. Where should I be putting it? I'm sure I'm missing something simple here.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    I tried the DefaultValue property and code in the form AfterUpdate event - neither is triggered by the paste.

    I think this will require an sql UPDATE action.

    CurrentDb.Execute "UPDATE tablename SET fieldname = Date() WHERE fieldname Is Null;

    or

    CurrentDb.Execute "UPDATE tablename SET fieldname = Nz(fieldname, Date())
    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.

  5. #5
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Using the OnCurrentEvent for your form, you can try this:

    If IsNull(Me.YourFieldName) Or Me.newrecord = True Then
    Me.SomeField = Date
    End If
    One additional thing: You will need to add on the Exit Event of the pasted field.
    Me.Dirty = False
    This worked for me.
    Last edited by burrina; 10-24-2014 at 12:43 PM. Reason: Code

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    I doubt that will work any different from AfterUpdate. Pasting does not trigger events.
    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.

  7. #7
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    See above response.

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    I knew I should have tested before speaking.
    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.

  9. #9
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Hmm, you mean I'm not the only one who does that?

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

Similar Threads

  1. Auto Fill a date in a field
    By SJJ in forum Access
    Replies: 1
    Last Post: 02-17-2014, 02:39 PM
  2. Replies: 3
    Last Post: 12-24-2013, 04:20 PM
  3. Lock field after auto date fill
    By DCV0204 in forum Forms
    Replies: 4
    Last Post: 11-25-2013, 08:53 AM
  4. Replies: 8
    Last Post: 11-13-2012, 03:36 PM
  5. Code to display latest record number field created?
    By rowardHoark in forum Programming
    Replies: 1
    Last Post: 01-31-2011, 08:03 AM

Tags for this Thread

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