Date validation within forms

LoneAngel666

New member
Local time
Today, 06:05
Joined
Nov 23, 2003
Messages
7
Hello all,

I'm having a situation with a form that I believe can be solved easily with some kind of validation code (I assume created with the expression builder).

There are two specific fields I am focusing on - a 'Start Date' and an 'End Date'. Both are short date format, and so accept exactly the same kind of data - no problems so far.

Now, first of all, the 'End Date' has to be AFTER the 'Start Date' - well that was easy enough to do - just:

>[Star_Date]

Right?

Now - the bit I find hard. How would I write an expression that ensured the 'End Date' could only ever be between three and twelve months AFTER the 'Start Date'? (Did that make sense?)

Hope someone can help - I need an answer soon :confused:

Rob
 
Just to stop the confusion, that is meant to say:

>[Start_Date]

Also, don't get confused - the fields are called 'Start_Date' and 'End_Date' (I just didn't include the underscores in my description of the problem.

Rob
 
You can add code to the BeforeUpdate event of End_Date:

Code:
If Not (End_Date >=  DateAdd("m", 3, Start_Date) And End_Date <=  DateAdd("m", 12, Start_Date)) Then
    Msgbox "End_Date out of range", vbOKOnly
    Cancel = True
End If
 
Whenever i try to enter that into the "Before Update" box for the "End Date" field, I get this error message:

"The expression you entered contains invalid syntax.
You may have entered an operator, such as the + operator, in an expression without a corresponding operand"

What do I do now? I entered exactly what you said, and nothing happened :S

Rob
 
When you add code for an event, you don't just paste it into the box next to the event property. You need to press the builder button and choose the code option. Then paste the code into the sub procedure that the builder built.
 

Users who are viewing this thread

Back
Top Bottom