re444
Feb 19 2009, 08:42 AM
I have one almost global, Validation Rule for my date fields and I'd like to write a user-defined function for this purpose just one time; but it seems that Access does not allow such a work! Is this true and if yes, what is the solution?
thanks,
Reza.
Alan_G
Feb 19 2009, 09:21 AM
Hi
You can most definitely write your own Public Function that can be called from anywhere in your db...what's the validation rule you want to use ?
re444
Feb 19 2009, 03:14 PM
It's just a simple rule that restricts the date values to be in current year(as a practice):
Public Function IsDateTrue(ctl As Control) As Boolean
If Year(ctl.Value) = Year(Date) Then
IsDateTrue = True
Else
IsDateTrue = False
End If
End Function
While used in a form, when the entry violates the rule, custom massage is displayed but when I correct it, this massage appears again(no matter what the content is)! And in a table, the function is not accessible from the builder.
Is the form of the function true, anyway?
Alan_G
Feb 19 2009, 03:57 PM
Hi
You can't call functions (or code in general) from a table.......
You can change the function to make it check for a valid date as well as check for current year to something like
CODE
Public Function IsDateTrue(ctl As Control) As Boolean
If IsDate(ctl.Value) Then
IsDateTrue = Year(ctl.Value) = Year(Date)
Else
IsDateTrue = False
End If
End Function
How are you calling the function, and from what form event ?
re444
Feb 20 2009, 05:11 PM
Your code is an improvement.
I'm calling the function from Validation Rule section of the control like: IsDateTrue([Control_Name])
thanks
Alan_G
Feb 20 2009, 05:30 PM
I'd use one the Event Procedures of the control...........
If you wanted to force a valid entry then you could use the Before Update event setting the Cancel argument equal to IsDateTrue.
re444
Feb 21 2009, 04:59 AM
It works when placed in Before Update event of the control.
thanks for your time!
Alan_G
Feb 21 2009, 08:34 AM
You're very welcome
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please
click here.