SetValue gives error when date data type - InfoPath Dev
in

InfoPath Dev

SetValue gives error when date data type

Last post 04-16-2008 10:38 AM by Greg Collins. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 04-15-2008 12:39 PM

    SetValue gives error when date data type

     I have been having problems trying to set the XPathNavigator in InfoPath form.  If I change the textbox from a date data type to a string data type, it works.  How can I convert or cast the XPathNaigator in InfoPath?  Here is what I have.

    Dim xnMyForm as XPathnavigator = Me.CreateNavigator

    Dim ns as XmlNamespaceManager = Me.NamespaceManager

    dClassDate = getFriDate()   ' getFriDate() gets the date of the upcoming Friday.  If today is Tuesday, it will return the date of Friday as #4/18/2008#

    'Here is where I get the error.

    xnMyForm.SelectSingleNode("/my:SharePointTraining/my:ClassDate", ns).SetValue(dClassDate)

     'If I change the date Picker, ClassDate,  on the form to a string data type, it works.

     
    Any suggestions on how to make this work?

     

    TIA

    Mike
     

     

  • 04-15-2008 04:07 PM In reply to

    Re: SetValue gives error when date data type

    The date format is a problem: "4/18/2008" is not a valid XML date... you need "2008-04-18".

    I'm not a VB expert, but is Me.CreateNavigator working? In C#, we us MainDataSource.CreateNavigator().... so I would assume that in VB it would be MainDataSource.CreateNavigator

  • 04-16-2008 09:28 AM In reply to

    Re: SetValue gives error when date data type

     Yes the me.CreateNavigator() works.  I got the sample from MS's site.

    I still have the same problem. 

    When I changed the format by using dMyDate.ToString("yyy-MM-dd") and then using xnMyForm.SelectSingleNode("/my:SharePointTraining/my:dClassDate", ns).SetValue(dMyDate), I still get the error regard the data type.  It seems that VSTA will not pass a date data type to an InfoPath form.  If I change the Date Picker to a string data type, it works.

  • 04-16-2008 09:34 AM In reply to

    Re: SetValue gives error when date data type

     I finally figured it out.  I had to change the Date Picker to a string data type.

  • 04-16-2008 10:38 AM In reply to

    Re: SetValue gives error when date data type

    You were close: dMyDate.ToString("yyy-MM-dd") is missing one "y".

    The easier method is dMyDate.ToString("s") which says to use the XML sortable format (which is what InfoPath is expecting) at: yyyy-MM-dd.

    If you make the field a "string" datatype then you miss out on a lot of useful built-in date validation. If you don't care about the validation and you don't need a valid date format, then string is what you want.

Page 1 of 1 (5 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.