Results 1 to 7 of 7
  1. #1
    Tuckejam is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Jan 2020
    Posts
    168

    On focus enter default date value

    Not sure why this one is so hard to figure out.



    I originally wanted to have a default date value (7/1/2019) entered into a textbox field on a form. but no matter what I tried it would always enter the default date of 12/30/1899 or #Type!


    not being able to figure this out I decided to try to figure out a much more complicated way of having a the default date value entered into the text box on focus, not surprising I couldn't figure that one out either.

    For reference
    this date is used as criteria in a query to find transactions between dates.

    The text box is

    Format: Short Date
    Text Format: Plain Text
    Show Date Picker: For dates

    No input mask as I read that in order to get the date picker to show there can be no input mask.
    and I need the date picker to still be available for use if the default date value is not used.

    Thanks for any help

  2. #2
    Mickjav is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Mar 2019
    Location
    Margate, Kent
    Posts
    123
    There a number of ways of doing this
    Add the default value into the property sheet like #07/01/2019#

    Or in code like: Me![Text13].DefaultValue = Format(Date, "\#mm\/dd\/yyyy\#") You can change the date with your own but assign it to a varible first
    like

    Code:
    Dim MyDate As Date
    MyDate = #7/1/2019#
    Me![Text13].DefaultValue = Format(MyDate, "\#mm\/dd\/yyyy\#")

  3. #3
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,530
    Set the Format property of the text box to: Short Date
    Set the Default Value property of the text box to: Format("07/01/2019", "dd\/mm\/yyyy")
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  4. #4
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    Or even better create a new table called tblSettings in which you add a field called DefaultDate and populate it with your desired date. Then in the desgin view of the form you select the date textbox and simply add =DLookUp("[DefaultDate]","[tblSettings]") in its DefaultValue property on the Data tab of the Properties window.
    See attached example (Date1 on Form1).
    This way you can change the date in the table instead of hard coding it into the design of your objects.
    Cheers,
    Vlad
    Attached Files Attached Files
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  5. #5
    Tuckejam is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Jan 2020
    Posts
    168
    oooohhhhh! BONUS ROUND!

    how about setting the default date as the previous July 1st.

    That's the start of our fiscal year and when searching transactions, generally wit will always be between the previous July 1st and now

  6. #6
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,101
    Use the DateSerial function with Year(Date()) -1 for the year argument, 7 for the month and 1 for the day
    Cheers,

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    You've already got good answers, but I thought I'd address why you got the bogus date in your effort. I suspect you had:

    Me.TextboxName = 7/1/2019

    or something similar. As noted literal dates need to be surrounded by #. Without that, Access assumed you entered a number rather than a date so you got 7 divided by 1 divided by 2019. The resulting fraction resulted in a time on the starting date of 12/30/1899. You could have fixed it with:

    Me.TextboxName = #7/1/2019#

    but the suggested table is a much better solution than hard-coding it.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 3
    Last Post: 04-08-2020, 02:44 AM
  2. Replies: 1
    Last Post: 09-26-2019, 08:49 AM
  3. Replies: 3
    Last Post: 08-18-2018, 01:29 PM
  4. Replies: 0
    Last Post: 04-12-2011, 10:37 AM
  5. Replies: 5
    Last Post: 02-06-2011, 04:32 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