Date in code - 'If' Statement

G

Guest

I have a form that where I do not want to allow data entry after 31/12/07
ie., December 31 2007.
In the AfterUpdate property of the [Date] field I have the code:
If [Date] > #31/12/07# Then DoCmd.CancelEvent

The code immediately corrects my coding to #12/31/2007# which is fine with
me, and has worked with all dates entered entered after 1/01/08 - BUT - now
it is also precluding entry for any date after 29/02/07. All dates up to
28/02/07 are fine - they are not excluded - but why is 29/02/07 causing a
problem.

I suspect the date # 12/31/2007# in the codeing is causing the problem - but
turning it upside down and inside out has not alleviated the problem.

Help
 
F

fredg

I have a form that where I do not want to allow data entry after 31/12/07
ie., December 31 2007.
In the AfterUpdate property of the [Date] field I have the code:
If [Date] > #31/12/07# Then DoCmd.CancelEvent

The code immediately corrects my coding to #12/31/2007# which is fine with
me, and has worked with all dates entered entered after 1/01/08 - BUT - now
it is also precluding entry for any date after 29/02/07. All dates up to
28/02/07 are fine - they are not excluded - but why is 29/02/07 causing a
problem.

I suspect the date # 12/31/2007# in the codeing is causing the problem - but
turning it upside down and inside out has not alleviated the problem.

Help

Most likely because there is NO Feb. 29 2007!
That's a leap year date, and this is not a leap year.
 
G

Guest

Yes thanks Fredg, - what a dill. How myopic can one become. The moment
after posting the question I realised my folly.
Truly, one born every minute.
--
Glynn


fredg said:
I have a form that where I do not want to allow data entry after 31/12/07
ie., December 31 2007.
In the AfterUpdate property of the [Date] field I have the code:
If [Date] > #31/12/07# Then DoCmd.CancelEvent

The code immediately corrects my coding to #12/31/2007# which is fine with
me, and has worked with all dates entered entered after 1/01/08 - BUT - now
it is also precluding entry for any date after 29/02/07. All dates up to
28/02/07 are fine - they are not excluded - but why is 29/02/07 causing a
problem.

I suspect the date # 12/31/2007# in the codeing is causing the problem - but
turning it upside down and inside out has not alleviated the problem.

Help

Most likely because there is NO Feb. 29 2007!
That's a leap year date, and this is not a leap year.
 
J

John Vinson

I have a form that where I do not want to allow data entry after 31/12/07
ie., December 31 2007.
In the AfterUpdate property of the [Date] field I have the code:
If [Date] > #31/12/07# Then DoCmd.CancelEvent

Umm???

Quite aside from the leapyear issue - the AfterUpdate event is TOO
LATE, is it not? The record has already been saved to disk.

I'd just use the BeforeUpdate event, not AfterUpdate; and set its
Cancel argument to True.

John W. Vinson[MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top