Results 1 to 10 of 10
  1. #1
    Lounger
    Join Date
    Jun 2011
    Posts
    25
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Date default values for forms

    Hi,

    I want to make the default value of one control on my form a year after the date of another control on my form. The first field is the start date of a contract, and generally the end date is a year after the start, so I want the default value to be a year after the start. In my form, in under default value for the end date, I have

    =DateAdd("yyyy",+1,[Start Date])

    but its not showing up when I go to my form. I am not quite sure how to fix this issue.

    Thanks in advance!

  2. #2
    Administrator
    Join Date
    Jun 2010
    Location
    Portugal
    Posts
    12,519
    Thanks
    152
    Thanked 1,398 Times in 1,221 Posts
    What's the name of the control where the start date is shown?

  3. #3
    Lounger
    Join Date
    Jun 2011
    Posts
    25
    Thanks
    2
    Thanked 0 Times in 0 Posts
    The name of the first control is "Start Date" and the name of the secont control is "Expiration Date"

  4. #4
    Administrator
    Join Date
    Jun 2010
    Location
    Portugal
    Posts
    12,519
    Thanks
    152
    Thanked 1,398 Times in 1,221 Posts
    The expression you are using seems correct to me, so the question is, has the Start Date control a value when you open the form?

  5. #5
    Lounger
    Join Date
    Jun 2011
    Posts
    25
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I am not sure if I completely understand you question.

    But when I open the form, there is no date in Start Date until I put it in.

    What I want to happen is that when I put a value in for Start Date on my form, the expiration date automatically fills in to become a year after the start date.

  6. #6
    Administrator
    Join Date
    Jun 2010
    Location
    Portugal
    Posts
    12,519
    Thanks
    152
    Thanked 1,398 Times in 1,221 Posts
    That's the problem, then. Without a value when the form opens, the default value is of no use.

    I suggest that you add an AfterUpdate Event procedure to the Start Date control and add something like this to the procedure:

    Me.Expiration_Date =DateAdd("yyyy",1,Me.Start_Date)


    I am not sure what Access version you are using, but in Access 2010, Access replaces spaces in control names with underscores (not sure how that was done before, don't think I ever used control names with spaces), so you may have to change the references to the control names. The best way would be to start typing the expression as above and Access's intellisense will give you the available control names, so that you can choose the correct ones.

  7. #7
    Lounger
    Join Date
    Jun 2011
    Posts
    25
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I am using Access 2007 and I added

    Me![Expiration Date] = DateAdd("yyyy", 1, Me![Start Date])

    to the AfterUpdate Procedure of Start Date. However, it is still not working. I have found that Access in 2007 requires control names with spaces to be put into brackets.

    It makes sense to put that into the after update section, and I thought it would fix it, but sadly it hasn't.

  8. #8
    Administrator
    Join Date
    Jun 2010
    Location
    Portugal
    Posts
    12,519
    Thanks
    152
    Thanked 1,398 Times in 1,221 Posts
    This is working for me in Access 2010. I don't think the syntax is Me![something], I think it is Me.[something].

    If it doesn't work, maybe post the database with just that form here and I will pick it up and make it work.

  9. #9
    Lounger
    Join Date
    Jun 2011
    Posts
    25
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Hello, I created a sample database with the code you have given and it works in that sample database. So I will just weed through mine to see what the issue is. Hopefully I shall find it! Thank you for your help

  10. #10
    Administrator
    Join Date
    Jun 2010
    Location
    Portugal
    Posts
    12,519
    Thanks
    152
    Thanked 1,398 Times in 1,221 Posts
    You're welcome.

Posting Permissions

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