Results 1 to 5 of 5
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Setting Default Date in a Text Box (2003)

    I'd like to set the default value of the Text2 text box in the Form3 form of the attached mdb to the last day of the month before the current one.
    I thought using
    =DateSerial(Year(Date()),Month(Date())-1,Choose(Month(Date()),31,gmese(Year(Date()),Month (Date())),31,30,31,30,31,31,30,31,30,31))
    as the text box's DefaultValue property would do the job but I get 1st May 2006 instead of 30 April 2006

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Setting Default Date in a Text Box (2003)

    This is much simpler:

    =DateSerial(Year(Date()),Month(Date()),0)

    The 0th day of a month is interpreted as the last day of the previous month.

  3. #3
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Setting Default Date in a Text Box (2003)

    <img src=/S/woops.gif border=0 alt=woops width=58 height=36>
    Thank you Hans, that's where your help is so valuable because there's no mention of such trick on help for the DateSerial function.

  4. #4
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Setting Default Date in a Text Box (2003)

    An alternative formula is: Date() - Day(Date())

    This also gives you the "0" day for the month, which Access interprets as the last day of the prior month.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  5. #5
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Setting Default Date in a Text Box (2003)

    That's another clever way of putting it.
    Thank you Mark <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •