Insert date into field - InfoPath Dev
in

InfoPath Dev

Insert date into field

Last post 02-21-2007 01:42 PM by shaun.nieves. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 02-20-2007 04:40 PM

    Insert date into field

    I'm using managed code to be used as a validator for a date field. I have a date picker and I want a validation error to fire if the date selected is less than 90 days from the current date. To accomplish this, I've used the onload event to calculate the date however I can an error when trying to push the date to my date field. Here is my code. Any help would be greatly appreciated.


    Dim dToday As Date = DateTime.Today()
    Dim vToday As Date = dToday.AddDays(-90)
    thisXDocument.DOM.selectSingleNode("my:myFields/my:Misc/my:Date-90").text = CDate(vToday)


    And here is the error


    System.Runtime.InteropServices.COMException
    '#PCDATA' is in nil content: <http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-12-12T22-07-01}Date-90>.

    at Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNode.set_text(String value)
    at Microsoft.Office.Interop.InfoPath.SemiTrust.DOMNodeWrapper.set_text(String value)
    at KINS_Incoming.KINS_Incoming.OnLoad(DocReturnEvent e)
    at Microsoft.Office.Interop.InfoPath.SemiTrust._XDocumentEventSink2_SinkHelper.OnLoad(DocReturnEvent pEvent)
    Shaun Nieves
    Sharepoint Manager
  • 02-20-2007 10:47 PM In reply to

    • Shiva
    • Top 25 Contributor
    • Joined on 04-15-2005
    • India
    • Posts 694
    Hi Shaun Nieves,

    Whenever we are trying set the one value to node it should be format of string only. Before you are setting the value, you have to convert it into string then try to set this value.
  • 02-21-2007 08:32 AM In reply to

    Thanks for the reply Shiva. I've converted to string and have even stripped that nil content error. Now the date field is populated however I'm getting an error that Only date allowed (example: 2001-03-14) and it's not firing the validation. If I reset the value of the text box the validation fires but not be default. Here is my code snippet


    Dim dToday As Date = DateTime.Today()
    Dim vToday As Date = dToday.AddDays(-90).ToString
    thisXDocument.DOM.selectSingleNode("my:myFields/my:Misc/my:Date-90").attributes.removeNamedItem("xsi:nil")
    thisXDocument.DOM.selectSingleNode("/my:myFields/my:Misc/my:Date-90").text = CDate(vToday)


    Thanks again for all your help!
    Shaun Nieves
    Sharepoint Manager
  • 02-21-2007 01:42 PM In reply to

    I think I may have figured it out using the bible according to Patrick. Here's my solution

    The following is in a OnBeforeChange event handler


    Dim dToday As Date = DateTime.Today()
    Dim vToday As Date = dToday.AddDays(-90).ToString

    Dim idNumber As String = e.Site.text
    If (idNumber > DateTime.Today) Then
    e.ReturnMessage = "The incoming date can not be greater than today"
    e.ReturnStatus = False
    ElseIf (idNumber < vToday) Then
    e.ReturnMessage = "The incoming date can not be less than 90 days ago"
    e.ReturnStatus = False
    End If


    I'd still like to know how to insert dates programattically though....
    Shaun Nieves
    Sharepoint Manager
Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.