Results 1 to 8 of 8
  1. #1
    cfljanet is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2013
    Posts
    58

    automatically advance date field by one day

    I have a form for which there is a new record for every day of the week. In practice this form is updated only every couple of weeks or so and as there are very often errors on entering the date, I wanted to automate it so that the date field defaults to the last date + 1. Simple I thought.

    I've tried everything over the years to no great success, but thought I had finally found the solution. It worked, until at some point it stopped working (I very rarely enter the data myself and I hadn't been told that it was not longer working), but the principle seems sound and I would like to tweak it back to life again.

    The set up is:

    • A field called Catchdate based on a field in a query with an input mask, formatted as Short Date and with a Default Value of: Iif(Max([CatchDate]) + 1 = Max([MaxDate]),[catchtest]+2,[MaxDate))
    • A hidden field called [MaxDate], formatted as Short Date with the Control Source as: DateAdd("d",1,[catchtest])
    • A hidden field called [catchtest], formatted as Short Date with the Control Source as: Max([CatchDate])


    Effectively the field [catchtest] returns the date of the last record in the table. MaxDate then adds 1 day onto the [Catchtest] date. The default on the Catch Date field provides a formula, which used to work, for updating the Catch Date field by 1 day every record.



    Now, however, the [CatchDate] field is correct on opening the form - it equals the MaxDate field - but after the first record the date defaults to 31/12/1899. And I don't know why.

    Does anyone have any ideas?

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    I would just walk the code.
    31/12/1899 is actually 1 in date number, so it is never getting a correct value, but a zero.

    Learn to walk your code with breakpoints and F8
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    After you save a record, check your variable and field values via the immediate window. I suspect that the date being returned is one(1) which IIRC would be represented as 12/31/1899
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    cfljanet is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2013
    Posts
    58
    There actually isn't any code in this. Just to text boxes with formulas as a control source and the data field with the default value specified. So I don't think F8 works with that?

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    You can debug.print the control values in various events?, as you are getting a zero, then adding your 1.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    cfljanet is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2013
    Posts
    58
    So the MaxDate field briefly flashes up 31/12/1899 before correcting itself. The catchtest field updates correctly straight away.

    It makes sense that the CatchDate field is basing it's default value on the first step of the MaxDate formula resolution and thus returning 31/12/1899. I'm not sure how to get around this though.

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    You could also move to a code solution perhaps, easier to debug. Something has changed, and it sounds like it must be the data, if nothing else has changed.
    You can also run various commands in the immediate window like DMax() to confirm values.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  8. #8
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Note: default value applies to new records only. If unsaved I dare say that this value is null for a bound field. Consider posting a compacted and zipped copy of your db.

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

Similar Threads

  1. Replies: 10
    Last Post: 04-01-2022, 08:10 PM
  2. Replies: 5
    Last Post: 07-02-2015, 10:49 AM
  3. Replies: 1
    Last Post: 05-13-2015, 03:29 AM
  4. advance date reminder
    By Denis in forum Database Design
    Replies: 1
    Last Post: 11-14-2010, 07:40 AM
  5. Replies: 1
    Last Post: 01-30-2010, 04:45 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