Results 1 to 9 of 9
  1. #1
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581

    Default Date

    In a form, I want to put make a default date. I want it to be January 1st of the current year. Any ideas?

  2. #2
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Cdate("01/01" & year(now))

  3. #3
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    Didn't work. Access changed it to: CDate("01/01" & Year(Now()))
    But, that gave me an error also.

  4. #4
    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,722

  5. #5
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,409
    if you observe what you have typed, you will see entering

    Cdate("01/01/" & year(Date))

    access automatically changes it to

    Cdate("01/01/" & year("Date"))

    This is because date is a function so needs the () at the end. Try

    Cdate("01/01/" & year(Date()))

  6. #6
    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,722
    Immediate window
    ?Cdate("01/01/" & year(Date))
    01-Jan-2017

    ?Cdate("01/01/" & year(Date()))
    01-Jan-2017

    ?date
    17-Jun-2017
    ?date()
    17-Jun-2017

    In a sub:

    Access /vba will remove the () and convert

    year(Date())) to year(Date))

    but still renders correct date.

    Code:
    Sub testdat()
    
    Debug.Print CDate("01/01/" & year(Date))  
    Debug.Print CDate("01/01/" & year(Date))    '<---- () removed when I  move off the line (syntax check)
    Debug.Print Date
    Debug.Print Date
    
    End Sub
    Result:

    01-Jan-2017
    01-Jan-2017
    17-Jun-2017
    17-Jun-2017

  7. #7
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,409
    yeah - but in the default property....

  8. #8
    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
    As Ajax said, in the Default Property, any Function used without the following () will be converted to a string...so

    Cdate("01/01/" & year(Date))

    will change to

    Cdate("01/01/" & year("Date"))

    Elsewhere is another thing entirely.

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

    All posts/responses based on Access 2003/2007

  9. #9
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    That worked perfectly. Thanks to all.

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

Similar Threads

  1. Replies: 1
    Last Post: 02-27-2017, 07:30 PM
  2. Date Default
    By Huddle in forum Forms
    Replies: 2
    Last Post: 01-29-2015, 05:41 PM
  3. Name & Date by Default
    By smarty84handsome in forum Reports
    Replies: 12
    Last Post: 01-21-2012, 12:22 AM
  4. Default date value
    By Wayne311 in forum Database Design
    Replies: 4
    Last Post: 01-15-2011, 05:38 PM
  5. Default Date in Date Fields
    By rickn in forum Access
    Replies: 5
    Last Post: 04-14-2010, 01:30 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