Results 1 to 5 of 5
  1. #1
    TheHarleygirl2005 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    34

    Default value doesn't update when date is changed

    I have an Attendance date on my form with a default value of =Date()


    I also have an Expiration date field with a default value of =DateAdd("yyyy",1,[AttendanceDate])

    These are working fine, however there are occasions when I need to change the Attendance date from today's date to something else (the date the course was taken) and I need the Expiration date to automatically update to one year from the new date. I'm guessing I just need to add a refresh or update code to the form but I'm unsure where to do that. Can you help?

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,948
    Cannot 'refresh' DefaultValue. DefaultValue property only executes when record is created, not when record is later edited. This is why should not save calculated value to table - data gets 'out of sync'. As much as possible, save raw data and do calcs when needed.

    Saving calculated value requires code that actually replaces the field value.
    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
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    In the AfterUpdate event of the AttendanceDate Control, use the code

    Me.ExpirationDate =DateAdd("yyyy",1,Me.AttendanceDate)

    This will only replace the date if you physically enter the date in AttendanceDate.

    And June7 is exactly right; the ExpirationDate Control should be Unbound, i.e. should not be saved in the underlying Table!

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    TheHarleygirl2005 is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    34
    This worked perfectly. My ExpirationDate is Unbound. It's located on a form where I enter information. Then I use a command button to run an Append Query which saves the info to another table. Thank you for your help!

  5. #5
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Glad we could help!

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

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

Similar Threads

  1. Replies: 19
    Last Post: 08-08-2013, 01:17 PM
  2. Date Picker Changed All Dates
    By deesy58 in forum Forms
    Replies: 11
    Last Post: 02-05-2013, 08:33 AM
  3. Replies: 12
    Last Post: 04-26-2012, 04:01 AM
  4. Date Stamp when a field is changed
    By winterh in forum Access
    Replies: 1
    Last Post: 04-25-2012, 07:27 AM
  5. Replies: 1
    Last Post: 03-20-2011, 05:59 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