Validate future date. - InfoPath Dev
in

InfoPath Dev

Validate future date.

Last post 10-04-2007 11:00 PM by Kalyan Gaddam. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 10-02-2007 06:28 AM

    Validate future date.

    Hi there,

    I have created a form in InfoPath 2003 and need to validate that the date selected (in a datepicker) is greater than today, but not more than 5 days in the future.

    I have created a validation event that uses the 'today()' function and set it to check error if the selected date is 'less than or equal to today()'. This works fine. The problem comes with the next part. I have created a 2nd validation event that checks whether the date 'is greater than today() + 5' but this doesn't work.

    I have hunted around on this forum and found some VBscript information that sounded like it may do the trick, however the 'OnValidate' or 'OnAfterChange' events don't seem to fire.
    Any help would be much appreciated.


    Many thanks,

    Skev

  • 10-02-2007 09:20 AM In reply to

    What I would do is use the datediff to calculate a field on load that is Today +5 then you can use a rule or code to validate if the entered date is greater than the calculated date.

  • 10-04-2007 11:00 PM In reply to

    Since there are no functions in Infopath to do this you have to use Code to do this
     
    public void date_OnValidate(DataDOMEvent e)

            {

                // Custom data validation because InfoPath does not have functions for date arithmetic

                if (e.Operation == "Insert")

                {

                    try

                    {

                        DateTime date = DateTime.Parse(e.NewValue.ToString());

                        if (date.CompareTo(DateTime.Today.AddDays(5)) > 0)

                        {

                            e.ReportError(e.Site, "Date cannot be more than 5 days away.",

                                                         false, null, 1, "modal");

                        }

                    }

                    catch (FormatException)

                    {

    i hope it helps you
    Kalyan G Reddy
    Infopath MVP 2007 and 2008
Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.