Results 1 to 3 of 3
  1. #1
    5 Star Lounger
    Join Date
    Mar 2001
    Thanked 0 Times in 0 Posts

    Assuming a date (97)

    I have a date field and on a form I want to key a date once and for this date to then be assumed when adding new records using the form. I added a textbox, called txtDate, and changed the Default Value for the date field control to =[txtDate]. Why is this not working correctly?? Andy.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Thanked 31 Times in 31 Posts

    Re: Assuming a date (97)

    If the user changes the value of txtDate, this won't be reflected automatically in the default value of the date field - you must set it anew in the AfterUpdate event of txtDate (I have used TransactionDate as name of the date field for illustration purposes):

    Private Sub txtDate_AfterUpdate()
    TransactionDate.DefaultValue = "=[txtDate]"
    End Sub

    Another possibility is not to use the DefaultValue property, but to set the date when inserting a new record:

    Private Sub Form_BeforeInsert(Cancel As Integer)
    TransactionDate = txtDate
    End Sub

  3. #3
    Gold Lounger
    Join Date
    Jun 2001
    Crystal Beach, FL, Florida, USA
    Thanked 40 Times in 39 Posts

    Re: Assuming a date (97)

    The DefaultValue for a field can be a constant or a build-in Access function, but not a user-defined function. If you wanted to set manually set the DefaultValue in the property sheet to a specific date, you'd put in a value something like this: "#1/1/03#". (If you wanted to Default to today's date, you'd put in "Date()". (In both cases, without the apostrophes).

    So, in code you have to do the same thing. In your form's AfterInsert event, put this:
    txtDate.DefaultValue = "#" & txtDate & "#"
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

Posting Permissions

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