Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2007
    Location
    Bedfordshire, UK
    Posts
    64

    Unanswered: Getting a date picker to default to current date

    I'm using Access 2003.
    I have a date picker control on a form which I would like to default to the current date when the form is opened for data entry.
    In the form load property I have placed the following code:

    Private Sub Form_Load()
    Me!DTPicker4.Value = Now()
    End Sub

    The database has 18 records in place for testing purposes. When I open the data entry form the first record defaults to the current date (even though the data was actually entered several days ago) and records 2 - 18 contain the date they were entered. If I try to create a new record - record 19 - it defaults to the value set in the control properties (April 1st).
    I need to ensure that records 1-18 retain their original dates of entry, and also need the date picker to default to current date ready to accept subsequent entries.
    Hope this is a clear enough description of the problem.

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    so you need to set the value when you start to add records, not when displayign records
    you need toplace you code in the appropriate event. not to certain which it is but is probably before add, or after add events
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Code:
    Private Sub Form_Current()
       If Me.NewRecord Then
         Me.DTPicker4.Value = Date
     End If
    End Sub
    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    Join Date
    Mar 2007
    Location
    Bedfordshire, UK
    Posts
    64
    Can't find "Before Add" event for the form, but have found an acceptable solution by placing the code in the "On Got Focus" event for the Date Picker control itself. This means that all the user has to do is click on the date and it immediately changes to the current date.
    Thanks for pointing me in the right direction healdem.

  5. #5
    Join Date
    Mar 2007
    Location
    Bedfordshire, UK
    Posts
    64
    Just read your reply, Missinglinq, after posting my last entry. That sounds even better, so I'll give it a go - would be much less clunky than my solution!

  6. #6
    Join Date
    Mar 2007
    Location
    Bedfordshire, UK
    Posts
    64
    I found Missinglinq's code works if I use Now() but Date doesn't work. But that's fine - I'm happy with that.
    However - and I don't know if this is anything to do with the date picker - when I try to run a report which I have set up using the data input via this form, I get a message which begins: "The expression is typed incorrectly, or it is too complex to be evaluated", and the report does not run. The report worked perfectly before I started trying to get the date picker to default to the current date! So I tried it again after removing all the code I've just put in and still get this message. Help!!

  7. #7
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    You don't have a field actually named Date, do you? It's a Reserved Word and using it as a name can lead to all kinds of problems.

    As to your new problem, do you have any idea what expression they're speaking of?

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Posting Permissions

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